Contract inheritance in solidity
Smart contracts can be inherited to extend the functionality. Solidity also supports multiple inheritance and polymorphism. We will look into each of them in detail with this recipe.
Getting ready
You need to have a working Ethereum installation for deploying and testing the smart contract. You can also use the Remix IDE to write and test the solidity code.
It is required to have a basic knowledge of solidity to understand this recipe. Go through Chapter 2, Smart Contract Development, for more information.
How to do it...
- Inherit contracts using the
is
keyword. The parent contract has to be imported or copied to the same file before inheriting:
contract A { ... } contract B is A { ... }
- When a contract inherits from multiple contracts, only a single contract is created in the blockchain. The other code from all the base contracts is copied into the created contract.
- In inheritance, the
final
function will be invoked while calling it by name. Call the functions...