-
What is the base contract?
The base contract also known as the parent contract are the ones from which Child/Derived contracts inherit from . -
Which functions are available for derived contracts?
All public and internal scoped functions and public state variables. -
What is hierarchical inheritance?
hierarchical inheritance is when single contract acts as a base contract for multiple derived contracts.
Nice answers @Nicco_Patel
âŚand welcome to the forum! I hope youâve been enjoying the course
Just one comment about Q2 âŚ
As well as state variables with public visibility, those with internal visibility are also available for derived contracts. The thing is that, unlike functions, state variables have internal visibility by default, and so including the internal
keyword is optional. So, state variables defined without a visibility keyword, and those marked internal
, are both available for derived contracts as state variables with internal visibility.
Just let me know if you have any questions.
- the parent
- public, internal
- 1 serves as parent for many
- the base contract is the parent contract
- all public and internal scoped functions.
- multiple separate contracts from the same parent.
- What is the base contract?
This is the parent contract in a inheritance class relationship. - 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?
A inheritance relationship where a single contract acts as a base contract for multiple derived contracts.
Nice answers @ryan_n
Just to confirm ⌠as with functions, it is the state variables defined in the base contract with public
or internal
visibility which are available for derived contracts â state variables marked private
are not available.
Let me know if you have any questions.
Hi! My answers:
1 A base contract is a contract whose code is inherited by another contract, a âchild contract.â
2 All public-scoped and internal-scoped functions from parent contracts are available for derived contracts.
3 Hierarchical inheritance is where a single contract acts as a base contract for multiple derived contracts.
Base (parent) contract is the contract where derived (child) contracts can inherit variables, functions modifiers and events from.
Derived contracts can inherit all the functions that are public and scoped internal from the base contract.
In hierarchial inheritance single smart contract is a base contract for multiple derived (child) contracts.
Nice answers @Davelopa
This is correct ⌠and only functions with public
and internal
visibility in the base contract will be available to be called from within the derived contract itself.
So, functions with public
and internal
visibility are inherited, as well as any functions in the base contract with external
visibility. However, unlike public
and internal
functions, inherited external
functions wonât be available to be called from within the derived contract; when the derived contract is deployed, they will only be available to call externally e.g. from Remix, the front-end interface of a dapp, or an external (i.e. non-derived) contract.
The only functions which arenât inherited are those with private
visibility.
Let me know if you have any questions
-
What is the base contract?
The base contract or parent contract is the one being inherited from. Itâs variables and functions are available to any subsequent child contracts. -
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?
In hierarchical inheritance, a single contract acts as a base contract for multiple derived contracts.
Nice answers @jrobbins
- What is the base contract?
⌠Itâs variables and functions are available to any subsequent child contracts.
But as youâve clarified in your answer to Q2, itâs the functions and state variables in the base contract with public
and internal
visibility which are available to its derived contract(s). Functions and state variables with private
visibility are not available.
A function in the base contract with external
visibility will be inherited by a derived contract, but only to the extent that, when the derived contract is deployed, this function will be available to call externally. An external
function in the base contract is not available to be called from within the derived contract itself.
Let me know if you have any questions.
- The main parent.
- All the functions of the parent.
- More than one child, and they have same parent.
Hi @DanDD,
Q3
Q1âWhat is the base contract?
- The main parent.
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.
Q2âWhich functions are available for derived contracts
- All the functions of the parent.
Not all of the functions in the parent contract are available. Functions with public or internal visibility are available for derived contracts, but not those with private visibility.
Let me know if anything is unclear, or if you have any questions
- The contract has a parent known as the derived class and the parent contract.
- Public and internal scoped functions.
- Similar to simple inheritance. However, a single contract acts as a base contract for multiple derived contracts.
- The base contract is the parent contract.
- All public and internal scoped functions and state variables are available to
- Hierarchical inheritance is is where a single contract acts as a base for multiple derived contracts.
Hi @Kunanon_Jarat,
Q2 & Q3
Q1âWhat is the base contract?
- The contract has a parent known as the derived class and the parent contract.
There is actually an error in the article when it refers to class, here.
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
So, to correct your answerâŚ
The child (or derived) contract inherits from a parent known as the base contract, the base class or the parent contract.
Let me know if you have any questions
- What is the base contract?
The base contract is the parent 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?
A single contract acts as a base contract for multiple derived contracts.
-
Parent contract, what all the child contract inherit from or âisâ.
-
Any public or internal functions
-
A base contract for multiple contracts
- A base contract is the one that another contract can inherit from.
- Derived contracts can use their parents public and internal functions.
- Hierarchical inheritance is when a parent contract has multiple children.
-
What is the base contract? - The contract from which you derived the child/derived contract
-
Which functions are available for derived contracts? Public and Internal visibility marked functions.
-
What is hierarchical inheritance? Multiple derived contracts using the same base contract. To have polymorphism you need to have poly (many) somethings that all have the same interface, but somewhat different behaviors (or why bother having poly anything?)