Inheritance Reading Assignment

  1. What is the base contract?

The Parent contract of the Child (derived) contract

  1. Which functions are available for derived contracts?

All Public and Internal functions and state variables are available for derived contracts.

  1. What is hierarchical inheritance?

A single contract is base contract for multiple derived contracts.

1 Like

What is a base contract?
A base contract is a parent contract

Which functions are available fro derived contracts?
All public and internal scoped fuctions, in addition to state variables

What is hierarchical inheritance?
Hierarchical inheritance is the instance where one contract acts base contract for several derived contracts

1 Like
  1. What is the base contract?
    Base Contract is the main parent contract.

  2. Which functions are available for derived contracts?
    All public and internal scoped
    functions and state variables are available for derived contracts.

  3. What is hierarchical inheritance?
    Hierarchal Inheritance is when there’s one parent contract and multiple child contracts inheriting from it.

1 Like

Nice answers @simfin94 :ok_hand:

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.

Nice answers @Divesh,

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.

  1. What is the base contract?
    The base contract is another name for the parent contract; the one that gets inherited by derived contracts.
  2. Which functions are available for derived contracts?
    All public and internal scoped functions from the base contract.
  3. What is hierarchical inheritance?
    The situation where multiple derived contracts come from the same base contract.
1 Like

Nice answers @blockchain.PE :ok_hand:

Just one comment …

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.

  1. What is the base contract?

The parent contract.

  1. Which functions are available for derived contracts?

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

  1. 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.

1 Like
  1. Another word for the base contract is parent contract
  2. All public and internal scoped functions and state variables of the parents contract are available for the derived contract
  3. When a single contract acts as parent contract acts for multiple child contracts
1 Like

Oh, thank you so much Jonathan for clarifying that, appreciate it!

1 Like
  1. It is the parent contract that child contracts derive from.

  2. All public and internal functions, as well as state variables, are available for derived contracts.

  3. A single contract acting as a base for multiple contracts.

1 Like

Nice answers @Aiden_Calhoun :ok_hand:

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.

Just let me know if you have any questions :slight_smile:

1 Like
  1. 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.

  2. Which functions are available for derived contracts?
    A derived contract can access all non-private members including state variables and internal methods .

  3. 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.

1 Like

Hi @HRMS2021,

Just to clarify a couple of points …

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 :slight_smile:

1 Like
  1. What is the base contract?

    When we have an inheritance relationship between contracts, the base contract is the contact from which the derived contract inherits variables and functions.

  2. Which functions are available for derived contracts?

    Derived contracts have all the public and internal functions inherited from its base contract.

  3. What is hierarchical inheritance?

    It happens when a contract is inherited by multiple contracts.

1 Like
  1. What is the base contract?
    • 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?
    • Single contract acts as base contract for multiple contracts
1 Like

Thank you @jon_m for your feedback, much appreciated :wink:

1 Like
  1. The base contract is the inital or starting contract that forms the base of other parent-child relationships

  2. The functions of the parent are available for derived contracts but it is also based on the visibility modifiers

  3. Hierarchical inheritance is when one contract acts as the base contract for multiple derived contracts

1 Like

What is the base contract?

  • The inherited contract or parent contract of a derived contract

Which functions are available for derived contracts?

  • All public and internal scoped functions

What is hierarchical inheritance?

  • A single contract acts as a base contract to multiple derived contracts.
1 Like

Hi @Shadowstep2003,

Q3 :ok_hand:

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.