Just to be clear… as with functions, its the state variables with public or internal visibility in the base contract which are inherited. So, any state variables with private visibility are not available for derived contracts.
Just to be clear, a base contract is any parent contract that is inherited by a derived contract. Within an inheritance structure there can be more than one base contract e.g.
// Multi-level inheritance structure
contract A { ... }
contract B is A { ... }
contract C is B { ... }
In this multi-level inheritance structure:
C is a derived contract
A is a base contract… but not the only base contract …
B is both a derived contract (of A), and a base contract (to C)
Basically…
parent contract = base contract
child contract = derived contract
They are just alternative terms for the same thing.
A derived contract doesn’t “come from” a base contract, it inherits its functionality (but not necessarily all of it). So just changing that one word will make your answer more accurate:
Hierarchical inheritance is the situation where multiple derived contracts inherit from the same base contract.
Which functions are available for derived contracts?
All public and internal scoped functions and state variables are available to derived contracts.
What is hierarchical inheritance?
Hierarchical inheritance is again similar to simple inheritance. Here, however, a single contract acts as a base contract for multiple derived contracts.
Q2 Which functions are available for derived contracts?
Just to confirm, in case it wasn’t clear …. as with functions, it is the public and internal state variables in the base contract which are inherited by the derived contract. State variables with private visibility are not available.
What is the base contract?
Solidity supports inheritance between smart contracts, where multiple contracts can be inherited into a single contract. The contract from which other contracts inherit features is known as a base contract, while the contract which inherits the features is called a derived contract.
Which functions are available for derived contracts?
A derived contract can access all non-private members including state variables and internal methods .
What is hierarchical inheritance?
Single inheritance passes functions, modifiers, events and variables from the parent to the child. And
Multi-level inheritance generates more than one parent-child relationship.
A derived contract also can’t access any functions in the base contract which have external visibility. In other words … functions with public or internal visibility are inherited, but those with external or private visibility are not available for derived contracts.
Your statement is correct in terms of state variables, because state variables cannot have external visibility. So, as with functions, state variables with public or internal visibility are inherited. But those with private visibility are not available for derived contracts.
In terms of other functionality… all events and modifiers in the base contract are available for the derived contract — no visibility is declared for either of these.
Q3 What is hierarchical inheritance?
Correct … when a single child contract inherits a single parent contract.
Correct … but more specifically, this is where at least one contract within the inheritance structure is both a child (inheriting a parent contract), and a parent (inherited by a child contract) e.g.
// Multi-level inheritance structure
contract A { ... } // A is a parent ... but not the only parent contract
contract B is A { ... } // B is both a child (of A), and a parent (to C)
contract C is B { ... } // C is a child contract
Hierarchical inheritance is where a single parent contract is inherited by more than one (multiple) child contracts e.g.
// Hierarchical inheritance structure
contract A { ... }
contract B is A { ... }
contract C is A { ... }
Let me know if anything is unclear, or if you have any questions
When we have an inheritance relationship between contracts, the base contract is the contact from which the derived contract inherits variables and functions.
Which functions are available for derived contracts?
Derived contracts have all the public and internal functions inherited from its base contract.
What is hierarchical inheritance?
It happens when a contract is inherited by multiple contracts.
Just to be clear, a base contract is any parent contract that is inherited by a derived contract. Within an inheritance structure there can be more than one base contract e.g.
// Multi-level inheritance structure
contract A { ... }
contract B is A { ... }
contract C is B { ... }
In this multi-level inheritance structure:
C is a derived contract
A is a base contract… but not the only base contract …
B is both a derived contract (of A), and a base contract (to C)
Basically…
parent contract = base contract
child contract = derived contract
They are just alternative terms for the same thing.
That’s right … and more specifically, it’s the functions in the parent contract with public or internal visibility which are inherited by the derived contract. Functions with external or private visibility are not available for derived contracts.