Inheritance in Solidity

Inheritance in solidity is basically extending the functionality of one contract into another contract. This is simply done by adding the keyword "IS" into the next contract.

Inheritance Solidity.PNG

We created two contracts named 'Bank' and 'mycontract' in the example above. To be able to extend any functionality from the contract 'Bank' into the contract 'mycontract', you use the key word 'IS' and the name of the contract, in this case, 'Bank' which you'll want to extend its functionality.

In the example below, we see the use of the keyword 'IS' in the second contract.

Inheritance Solidity2.PNG This means that the functionalities in the 'Bank' contract has been extended and can be accessed by the 'mycontract' contract.

In any case, you would want to extend the contract attribute to just another contract and do not want the outside world to access it. You can use the "internal" Keyword. This restricts the access of the functionality to just other contracts that it has been extended to. It cannot be accessed by the outside contract.

Inheritance Solidity3.PNG

This is DAY12 of my learning in public and sharing what I have learnt about Solidity. You can follow me on Twitter, to follow my Journey.

Other resources on Inheritance in Solidity: (bitdegree.org/learn/solidity-inheritance) (tutorialspoint.com/solidity/solidity_inheri..) and remember to always read the solidity documentation here Solidity Docs