0
0
Blockchain / Solidityprogramming~10 mins

Abstract contracts in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an abstract contract in Solidity.

Blockchain / Solidity
abstract contract [1] {
    function doSomething() public virtual;
}
Drag options to blanks, or click blank then click option'
AMyAbstract
Bcontract
Cinterface
Dlibrary
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'interface' or 'library' instead of a contract name.
Omitting the contract name.
2fill in blank
medium

Complete the code to declare an abstract function inside an abstract contract.

Blockchain / Solidity
abstract contract Base {
    function [1] public virtual;
}
Drag options to blanks, or click blank then click option'
AdoSomething() public
BdoSomething()
CdoSomething() public override
DdoSomething() public virtual override
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a function body in an abstract function.
Using override in the abstract function declaration.
3fill in blank
hard

Fix the error in the derived contract by completing the function override.

Blockchain / Solidity
abstract contract Base {
    function doSomething() public virtual;
}

contract Derived is Base {
    function doSomething() public override [1];
}
Drag options to blanks, or click blank then click option'
A{}
B;
C()
Dvirtual
Attempts:
3 left
💡 Hint
Common Mistakes
Ending the function with a semicolon instead of braces.
Omitting the function body.
4fill in blank
hard

Fill both blanks to declare an abstract contract with an abstract function and a state variable.

Blockchain / Solidity
abstract contract [1] {
    uint public [2];
    function doWork() public virtual;
}
Drag options to blanks, or click blank then click option'
AWorker
Bvalue
Ccount
DTask
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid names for contract or variable.
Trying to assign a value to the abstract function.
5fill in blank
hard

Fill all three blanks to implement a derived contract that overrides an abstract function and sets a state variable.

Blockchain / Solidity
abstract contract Base {
    uint public number;
    function setNumber(uint _num) public virtual;
}

contract Derived is Base {
    function [1](uint _num) public override {
        [2] = _num;
    }

    function getNumber() public view returns (uint) {
        return [3];
    }
}
Drag options to blanks, or click blank then click option'
AsetNumber
Bnumber
DsetNum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than the abstract function.
Using a wrong variable name inside the function.