Inheritance
Learn about inheritance in Solidity.
We'll cover the following
One of the key components of an object-oriented programming language is inheritance. It’s a technique for enhancing a program’s functionality that separates the code, lessens dependence, and improves the reusability of the current code.
Inheritance between smart contracts is supported by Solidity, allowing several contracts to be inherited into a single contract. A derived contract inherits features from a base contract, which is the contract from which additional contracts derive their features. They are simply known as parent-child contracts.
In Solidity, only internal and public modifiers are capable of inheritance. Some of Solidity’s major highlights include:
All nonprivate members, including state variables and internal methods, are accessible to derived contracts. However, employing this is restricted.
Function overriding is permitted as long as the function signature is maintained. The compilation will fail if the output parameters are different.
The
super
keyword or the super contract name can invoke a super contract’s function.Function calls made with
super
give precedence to the majority of derived contracts when there are multiple inheritances.
We can use the is
keyword to inherit the contract as follows:
Get hands-on with 1200+ tech skills courses.