- What is the base contract?
Is a parent contract - Which functions are available for derived contracts?
All public and internal functions - What is hierarchical inheritance?
There is a base contract for multiple child contracts that derive from it.
Q1. What is the base contract?
A1. Parent Contract
Q2. Which functions are available for derived contracts?
A2. All public and internal scoped functions
Q3. What is hierarchical inheritance?
A3. This is where single contract acts as a base contract for multiple derived contracts
- What is the base contract?
- The parent contract or highest level contract
- Which functions are available for derived contracts?
- Public and internal scoped functions
- What is hierarchical inheritance?
- Where several contracts can inherit the parent one
1. What is the base contract?
In solidity contracts can have parent child relationships. A contract can derive variables, functions, modifiers and events from another contract. The parent contract is also called a base contract.
2. Which functions are available for derived contracts?
Public and internal.
3. What is hierarchical inheritance?
A parent contract can have multiple derived classes. In this case the inhertance is called hierarchical.
A
/ \
B C
B is A, C is A
- The contract that is inherited is called the parent contract and the contract that inherits is called the child contract .
- All public and internal scoped functions and state variables are available to derived contracts.
- Hierarchical inheritance is again similar to simple inheritance. Here, however, a single contract acts as a base contract for multiple derived contracts.
-
What is the base contract?
It is a parent contract. -
Which functions are available for derived contracts?
The parentâs function are available to the derived contract. -
What is hierarchical inheritance?
It is similar to single inheritance.
1.What is the base contract?
It is a Parent Contract.
2.Which functions are available for derived contracts?
All public and internal scoped functions and state variables are available to derived contracts.
3.What is hierarchical inheritance?
A single contract acts as a base contract for multiple derived contracts.
- the parent contract.
- Public and internal scoped functions.
- a single contract acts as a base contract for multiple derived contracts.
- What is the base contract?
A: the parent contract - Which functions are available for derived contracts?
A: all public and internal functions - What is hierarchical inheritance?
A: Hierarchical inheritance is similar to simple inheritance except a single contract acts as a base contract for multiple derived contracts.
- What is the base contract?
- Which functions are available for derived contracts?
- What is hierarchical inheritance?
- The parent contract
- All functions defined in the derived contract itself and the public and internal ones of their parents
- When a base contract acts as a parent for multiple derived contracts
- The base contract is the contract is the contract inherited by other contract
- Only public and internal functions
- It is a inheritance that from the base contract arrive to create a big strong inherited family of contract
Nice answers @giomiri
Just a couple of observationsâŚ
⌠as long as there is more than one âsiblingâ contract derived from the single parent, then itâs hierarchical inheritance. We use this term when there is one level of inheritance from the parent contract. If there is more than one level then we would have either multi-level or multiple inheritance.
- Base Contract is the Father contract from which Child Contracts(also known as Derived contracts) are derived.
- All Public and Internal Scoped Functions and State Variables are available for derived Contracts.
- Hierarchical Inheritance is where a Single Contract is used as a Base Contract for multiple derived Contracts.
1. What is the base contract?
A base contract is a parent contract of a child contract, that has been derived from that base contract. The child inherits code from itâs base contracts. For that the Solidity compiler copies the base contract bytecode into derived contract bytecode.
2. Which functions are available for derived contracts?
From the base contract all public and internal scoped functions and state variables are available fto the derived contracts. If not all abstract functions are implemented in the derived contract, the contract is still abstract and no instance of that contract can be created, so it cannot be used.
3. What is hierarchical inheritance?
A hierarchical inheritance exists, when a contract acts a a base contract for more than one derived contracts.
Iâm not sure if the article is correct in the following aspects:
-
The phrase âSimilarly, the contract has a parent known as the derived class and the parent contract is known as a base contract .â do not seem logical to me. Shouldnât it be âSimilarly, the contract has a child known as the derived class and the parent contract is known as a base contract .â?
-
Shouldnât the arrows in the Multiple Inheritance diagram point upwards?
-
The code example for âInterfacesâ appears to be identical to the code example for âAbstract Contractsâ. I think the first âAddNumberâ in the code example for âInterfacesâ should not have a function body.
Hi @Laurenzius,
Well spotted!
Yes, this is incorrect. Contracts in Solidity operate in a similar way to classes in other object-oriented programming languages, and therefore the following are alternative names for the same thing:
parent contract = base contract = base class
child contract = derived contract = derived class
As the arrows represent the inheritance relationships, then I think that whether they point upwards or downwards is a matter of how you visually conceptualise these relationships. However, the diagrams in the article are confusing because the direction of the arrows is not applied consistently, which is your point. I think that, perhaps, straight lines instead of arrows would be better, like in a family tree, because itâs the relationship we want to highlight, not direction.
Yes, this is an error. The author has incorrectly duplicated the Abstract Contracts example.
In terms of abstract contracts and interfaces, this article is also quite out of date now. For example, as well as the point youâve made that all functions in an interface should just be declarations without function bodies, all function declarations in an interface should now also be marked with external
visibility. Additionally, Solidity v0.6.0 introduced the keywords abstract
, virtual
and override
, which are now also used in these situations. If you are interested, you can read about this in more detail in the Solidity documentation:
https://docs.soliditylang.org/en/v0.6.0/contracts.html#abstract-contracts
https://docs.soliditylang.org/en/v0.6.0/contracts.html#interfaces
Hi @jon_m,
thank you very much for your detailed comments. I am happy hear to that my assumptions has been right.
I appreciate that Solidity v0.6.0 has become more precise here. So the improved concept seems to be more like what I know from Java.
-
What is the base contract?
Parent contract = base contract -
Which functions are available for derived contracts?
Function available all public and internal and the state variables -
What is hierarchical inheritance?
similar to single contract , this hierarchical inheritance is when a parent contact act as base contract for multiple childs
Nice answers @ElyRamos
YesâŚand just to be clear, itâs the public and internal state variables which are inherited as well (i.e. both private functions and private state variables are not inherited).
What is the base contract?
When using inheritance the parent contract is called the base contract.
Which functions are available for derived contracts?
all public and internal scoped functions
What is hierarchical inheritance?
Hierarchical inheritance is where a base contract ( parent contract ) is inherited by more than one derived contract thus a single parent contract can have multiple child contracts.