Learn how to make contracts that must be inherited by another contract.
Abstract contracts can’t exist on their own. Their functionality can only be utilized by a contract that inherits from them. In this lesson, you’ll learn how to create an abstract contract.
By the end of this lesson you should be able to:
Continue with your Inheritance.sol
file. Add ContractD
as an abstract contract
. Add a virtual
function called whoAreYou
function, but do not add any implementation for that function.
Reveal code
Update ContractA
to inherit from ContractD
.
You’ll get a slightly confusing error that ContractA
needs to be marked as abstract
. Doing so is not the correct fix.
The clue for the correct solution is further down: Note: Missing implementation:
Only abstract
contracts can declare functions that are not implemented. To fix this, provide an override
implementation for whoAreYou
in ContractA
:
Reveal code
In this lesson, you’ve learned how to implement and inherit from an abstract contract.