Blog

Multiple Inheritance

Multiple inheritance allows a contract to inherit from more than one parent contract. This feature enables developers to combine functionalities from multiple contracts into a single child contract.

To implement multiple inheritance in Solidity, you simply separate the parent contracts with commas in the contract declaration.

Here's the basic syntax:





The order of parent contracts matters. Functions and state variables are inherited from parent contracts in the order they are listed in the inheritance declaration. If there are conflicting function names or state variables in the parent contracts, the compiler will raise an error, and you'll need to use explicit override keywords in the child contract to resolve the ambiguity.

In cases where there is a chain of inheritance where a child contract inherits from two or more contracts that ultimately inherit from a common ancestor, there can be ambiguity known as the "diamond inheritance problem." Solidity resolves this ambiguity using the C3 Linearization algorithm to determine the order in which parent contracts are searched for function and variable lookups.