Inheritance Reading Assignment

  1. What is the base contract?

The base contract is the parent contract to its child. A base contract can also be a derivation - see example of multi-level inheritance in the article.

  1. Which functions are available for derived contracts?

Functions of parent contracts are available to derived contracts - functions with public and internal visibility are inherited by derived contracts.

  1. What is hierarchical inheritance?

This is when one contract is the base contract for multiple derived contracts.

1 Like
  1. A base contract is similar to a parent contract in where there will be another contract that is derived form the base.
  2. The functions of the base contract.
  3. It is where a single contract acts a base contract for multiple derived contracts.
1 Like

Nice answers @CryptoByNight :ok_hand:

Here, I assume you mean that a base contract can also be a derived contract from another base contract e.g. contract B in the following example …

Yes … functions in the parent contract with public and internal visibility are inherited and therefore available for the derived contract. Whereas functions in the parent contract with external and private visibility are not inherited and therefore not available for the derived contract.

1 Like

Hi @Jules,

Q3 :ok_hand:

Q1 What is the base contract?

Q2 Which functions are available for derived contracts?

Yes , but not all of them…
Functions in the base contract with public or internal visibility are inherited and available for the derived contract; but those with external or private visibility are not inherited.

Just let me know if you have any questions.

1 Like
  1. The base contract is a parent contract of a child/derived contract.

  2. Functions in the parent contract with public and internal visibility are available to the derived contract. However, functions with external and private visibility are not available.

  3. Hierarchical inheritance is when a single contract acts as a base contract for multiple derived contracts.

1 Like
  1. The base contract in the parent contract inherited by derived classes.
  2. Public and internal functions.
  3. Multiple contracts are derived from the same base contract.
1 Like
  1. It’s a parent contract - the conract we inherit from
  2. public and internal
  3. It’s just a concept that you can inherit in a non-linear way. Like many things in programming, it’s just a fancy expression, but quite straightforward thing XD
1 Like

Nice answers @JJ_FX :ok_hand:

In terms of Q3 What is hierarchical inheritance?

While this is true, we need to be a bit more specific, in order to distinguish hierarchical inheritance from multiple inheritance …

Hierarchical inheritance is where more than one child contract inherits from the same, single parent contract e.g.

contract A { ... }
contract B is A { ... }
contract C is A { ... }

In contrast, multiple inheritance is where the same, single child contract inherits from more than one parent contract e.g.

contract D is A,B,C { ... }

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

1 Like

What is the base contract?
Base contract is the contract whereby the derived contracts copy the bytecode from. It is also known as Parent Contract.

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

What is hierarchical inheritance?
In a hierarchical inheritance, a single contract acts as a base contract for multiple derived contracts, whereby more than 1 contract is derived from a single base contract.

1 Like
  1. Base contract is the parent contract and the one who inherits is called a child contract.
  2. All the public and internal scoped functions are available in a derived contract.
  3. hierarchical inheritance is like a pyramid that is similar to simple inheritance but there are 2 child that inherits the base contract.
1 Like

Nice answers @Flippy :ok_hand:

Just a couple of comments about your answer to Q3 …

Correct … but the correct term is single inheritance — where a single derived contract inherits from a single base contract.

Correct … but there could also be more than 2 child contracts. Hierarchical inheritance is where the same, single parent contract is inherited by more than one child contract (multiple child contracts).

Let me know if you have any questions.

1 Like
  1. What is the base contract?
    A base contract is the first contract is also known as the parent contract. It is where all derived contracts inherit their traits from.

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

  3. What is hierarchical inheritance?
    This is when a single contract acts as a base contract for multiple derived contracts.

1 Like

Nice answers @unwise_guy :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…
base contract = parent contract
derived contract = child contract
They are just alternative terms for the same thing.

Just let me know if you have any questions.

  1. The parent contract from which the contract in question inherents properties.
  2. Public and internal functions.
  3. A single contract forming the basis for multiple other contracts.
1 Like

Nice answers @Lennart_Lucas :ok_hand:

Just to be clear… hierarchical inheritance is where "a single base contract is inherited by multiple derived contracts."

1 Like

1. What is the base contract?

The base contract is also known as a parent contract. A parent contract / base contract is the contract that is inherited.

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?

Hierarchical inheritance is similar to simple inheritance.

1 Like

Hi @Crownie,

Q1 & Q2:ok_hand:

Hierarchical inheritance is where more than one child contract inherits from the same, single parent contract e.g.

contract A { ... }
contract B is A { ... }
contract C is A { ... }

Whereas single inheritance is where a single child contract inherits from a single parent contract.

contract A { ... }
contract B is A { ... }

The correct term is single inheritance (not simple inheritance)

Let me know if you have any questions.

1 Like

1. What is the base contract?

The base contract is the contract that is inherited, it is the parent contract. The child contract inherits from the parent contract.

2. Which functions are available for derived contracts?

This is wrong

Both public and internal functions can be called from the base contract and all the contracts that inherit from it.

Correction is here.

3. What is hierarchical inheritance?

Hierarchical inheritance is when many different contracts inherit from the same base contract, i.e: the contracts B, C, and D inherit from the same base contract, contract A.

contract A { }
contract B is A { }
contract C is A { }
contract D is A { }
1 Like

Ah, right. Makes a lot more sense, thank you!

1 Like
  1. It is the parent contract, first in hierarchy.
  2. Functions defined as public or internal.
  3. Hierarchy of child contracts under 1 parent contract.
1 Like