Inheritance Reading Assignment

1. What is the base contract?
The parent contract
2. Which functions are available for derived contracts?
All public or internal functions and state variables are available for derived contracts.
3. What is hierarchical inheritance?
Its wen there is one parent contract with multiple child contracts deriving from it.

1 Like

exactly, sorry for the mistype

1 Like

Nice answers @Dominik_Szopa :ok_hand:

Just to confirm…

Yes…and as with functions, it’s the public and internal state variables which are inherited (i.e. private state variables are not inherited).

Hi @mburtonshaw,

Nice answers :ok_hand:

And just to confirm…

This is correct, but more specifically, hierarchical inheritance is where more than one child contract is derived from the same parent contract.

A base contract is the parent contract.

All functions that are specified as being of public or internal scope.

It is when a base contract has two or more child contracts and when these child contracts are not derived from each other.

1 Like
  1. The base contract is the parent contract in which other contracts can inherit functions, state variables (global variables), events and modifiers from.

  2. Derived contracts will inherit public and internal functions from their parent contract.

  3. Hierarchical inheritance goes something like this:

A <-- B
A <-- C
C <-- D
C <-- E

A is the base contract. B inherits from A, meaning B is an ‘A’ type contract. C inherits from A, meaning C is also an ‘A’ type contract. D inherits from C, meaning D is a ‘C’ type contract. E inherits from C meaning E is a ‘C’ type contract.

In this scenario we have a hierarchy of inheritance as we have different levels/tiers of inheritance. A being the top-level base contract in which multiple contracts inherit from it (B,C). B and C are the second-level. D and E are the children to C forming the third-level in the hierarchy.

1 Like
  1. A base contract is also known as the Parent contract from which a child contract is derived.
  2. All public & internal functions from the parent contract.
  3. In this type of inheritance there is a single base contract from which 2 or more child contracts are derived.
1 Like

yes private state variables are not inherited

1 Like

Excellent answers @Jesal_Patel :muscle:

Just to confirm…you only need 1 level of multiple derived contracts to form hierarchical inheritance i.e.

But your example is also correct and very well explained :+1:

1 Like

I just decided to create an extra case which was unnecessary :joy:. Yes only 1 level would be enough to form hierarchical inheritance as you said :slight_smile:.

1 Like
  1. Base contract is a Parent Contract child contract inherits from.
  2. All public and internal functions are available for derived contracts.
  3. In hierarchical inheritance base contract is inherited by multiple child contracts.
1 Like
  1. The Parent Contract is know as the base contract.

  2. All public and internal scoped
    functions and state variables are available to derived contracts.

  3. A single contract which acts as a base contract for multiple derived contracts.

1 Like
  1. It is a parent contract.
  2. All public and internal scoped functions and state variables are available to derived contracts.
  3. A single contract acts as a base contract for multiple derived contracts.
1 Like

1 - parent contrat
2- All public and internal scoped functions
3- hierarchical inheritance is a single contract and acts as a base contract for multiple derived contracts

  1. The parent contract - the contract that is inherited by the child contract/s.
  2. All functions of the parent contract/s.
  3. Similar to a tree structure, & all children contracts inherit the higher level contracts.
  1. The contract which is inherited by another contract.
  2. All functions in the base contract(s) are available for derived contracts.
  3. One contract is inherited by multiple contracts.

1.) A base contract, or parent contract, passes on its functions to its derived contracts.
2.) Derived contracts can do any public or internal function that the parent contract can, and also any functions involving state variable.
3.) Hierarchical inheritance is when a single contract acts the base for multiple derived contracts.

  1. What is the base contract? Parent Contracts

  2. Which functions are available for derived contracts? Public and internal functions are available in a derived contract

  3. What is hierarchical inheritance? Single contract acting as the base contract for multiple derived contracts

  • What is the base contract?
    the base contract is the parent contract; the contract that is inherited

  • Which functions are available for derived contracts?
    public and internal functions

  • What is hierarchical inheritance?
    hierarchical inheritance is similar to simple inheritance; a single contract acts as a base contract for multiple derived contracts

  1. What is the base contract?
    The contract that is inherited is called the parent contract also known as base 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?
    Similar to single inheritance a single contract acts as a base contract for multiple derived contracts.