Complete the code to declare an abstract contract in Solidity.
abstract contract [1] {
function doSomething() public virtual;
}The keyword abstract is used to declare an abstract contract. Here, MyAbstract is the contract name.
Complete the code to declare an abstract function inside an abstract contract.
abstract contract Base {
function [1] public virtual;
}override in the abstract function declaration.Abstract functions are declared with their signature only, ending with a semicolon. The virtual keyword allows overriding.
Fix the error in the derived contract by completing the function override.
abstract contract Base {
function doSomething() public virtual;
}
contract Derived is Base {
function doSomething() public override [1];
}
When overriding an abstract function, you must provide a function body enclosed in curly braces {}.
Fill both blanks to declare an abstract contract with an abstract function and a state variable.
abstract contract [1] { uint public [2]; function doWork() public virtual; }
The contract is named Worker and the state variable is value. Abstract functions have no body.
Fill all three blanks to implement a derived contract that overrides an abstract function and sets a state variable.
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];
}
}The derived contract overrides setNumber to set the state variable number. The getter returns number.