0
0
Blockchain / Solidityprogramming~20 mins

Abstract contracts in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Abstract Contract Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of an abstract contract inheritance
What is the output when deploying and calling getValue() from the ConcreteContract below?
Blockchain / Solidity
abstract contract AbstractContract {
    function getValue() public virtual returns (string memory);
}

contract ConcreteContract is AbstractContract {
    function getValue() public override returns (string memory) {
        return "Hello from Concrete!";
    }
}
A"Hello from Concrete!"
BCompilation error: Missing implementation of getValue
C"Hello from Abstract!"
DRuntime error: Abstract function called
Attempts:
2 left
💡 Hint
Remember that abstract contracts require derived contracts to implement abstract functions.
🧠 Conceptual
intermediate
1:30remaining
Purpose of abstract contracts
What is the main purpose of using abstract contracts in blockchain smart contract development?
ATo define a contract with some functions unimplemented, forcing derived contracts to implement them
BTo deploy a contract that cannot be inherited
CTo create a contract that stores data permanently without functions
DTo automatically generate user interfaces for contracts
Attempts:
2 left
💡 Hint
Think about contracts that act like blueprints.
🔧 Debug
advanced
2:00remaining
Identify the error in abstract contract implementation
What error will the Solidity compiler produce for the following code?
Blockchain / Solidity
abstract contract Base {
    function foo() public virtual returns (string memory);
}

contract Derived is Base {
    // Missing override of foo
}
ARuntimeError: Abstract function called
BTypeError: Derived contract must implement function 'foo()' or be declared abstract
CSyntaxError: Missing semicolon after function declaration
DNo error, code compiles successfully
Attempts:
2 left
💡 Hint
Check if Derived implements all abstract functions.
📝 Syntax
advanced
1:30remaining
Correct syntax for abstract function declaration
Which option shows the correct syntax to declare an abstract function in Solidity?
Aabstract function doSomething() public returns (uint);
Bfunction doSomething() public returns (uint) {}
Cfunction doSomething() public virtual returns (uint);
Dfunction doSomething() public abstract returns (uint) {}
Attempts:
2 left
💡 Hint
Abstract functions have no body and use the virtual keyword.
🚀 Application
expert
2:30remaining
Number of items in a contract inheritance chain
Given the following contracts, how many contracts must be deployed to use FinalContract and call getData() successfully?
Blockchain / Solidity
abstract contract A {
    function getData() public virtual returns (string memory);
}

abstract contract B is A {
    function getData() public virtual override returns (string memory);
}

contract FinalContract is B {
    function getData() public override returns (string memory) {
        return "Data from Final";
    }
}
ANo contracts can be deployed because of abstract functions
BTwo contracts: A and FinalContract
CThree contracts: A, B, and FinalContract
DOnly one contract: FinalContract
Attempts:
2 left
💡 Hint
Only concrete contracts can be deployed.