Inheritance Reading Assignment

  1. The base contract is the contract that is inherited (the parent).
  2. The parent contract’s public and internal functions are available for derived contracts.
  3. A hierarchical inheritance is when a single contract acts as a parent for multiple derived contracts.
2 Likes
  1. What is the base contract?
    The base contract is the contract that is being inherited also know as the PARENT contract.

  2. Which functions are available for derived contracts?
    the functions that are available for derived contracts, are function that has the public or external visibility scope.

  3. What is hierarchical inheritance?
    This is a kind of inheritance where one (1) contract acts as the base contract to multiple derived contracts

1 Like

Nice answers @LELUK911 :ok_hand:

Just one comment about the answer to Q2 …

This is correct in terms of which functions in the base contract are inherited by a derived contract: the only functions which aren’t inherited are those with private visibility.

However, unlike public and internal functions, an external function in the base contract is not available to be called from within the derived contract itself. It 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 e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract.

Let me know if anything is unclear, or if you have any questions :slight_smile:

1 Like

Hi @Arch.xyz,

Q1 & Q3 :ok_hand:

No … functions in the base contract with public or internal visibility are inherited and available to be called from within a derived contract.

A function in the base contract with external visibility will also 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 e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract. However, unlike public and internal functions, an external function in the base contract is not available to be called from within the derived contract itself.

The only functions which aren’t inherited are those with private visibility.

Just let me know if anything is unclear, or if you have any questions.

I understand now… thank you very much

1 Like

1- the base contract is the parent contract, where everthing starts.
2- derived contracts can use functions( public, internal) and state variables.
3- in a hierarchical inheritance, we got a “base” contract that originates multiple derived contracts.

1 Like

Hi @Wyse_Sousa,

These are mostly good answers :ok_hand:

Just a couple of clarifications …

Yes … but not “everything” starts in the base/parent contract. A derived contract only inherits some of its functionality from its parent, most of it usually being unique to itself.

Q2 Which functions are available for derived contracts?

As with functions, the state variables in the base contract which are available for derived contracts are those with public or internal visibility. State variables with private visibility are not available.

Let me know if you have any questions :slight_smile:

1 Like
  1. What is the base contract?

Inheritance is the process of defining multiple contracts, that are related to each other, through parent-child relationships. The contract that is inherited is the parent contract or the base contract. The contract that inherits is the child contract or the derived contract/class.

  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?

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

1 Like

Nice answers @Liquidbaker89 :ok_hand:

Just one clarification …

As with functions, the state variables in the base contract which are available for derived contracts are those with public or internal visibility. State variables with private visibility are not available.

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

thank you for the clarifications!

1 Like

Thank you for the clarification @jon_m

1 Like
  1. The base contract is the parent contract.

  2. Internal and public functions and state variables are available to derived contracts.

  3. A hierarchical inheritance is a single base contract, that is inherited by multiple derived contracts.

1 Like
  1. What is the base contract?
    It is the parent contract, the child contract will inherit from it

  2. Which functions are available for derived contracts?
    All of them

  3. What is hierarchical inheritance?
    It is a inheritance that a single contract act as base contract for multiple contracts

1 Like

Hi @Abel,

Q1 & Q3 :ok_hand:

No… not all of the functions in the base contract are available. Functions with public or internal visibility are available for derived contracts, but not those with private visibility.

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 e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract. However, unlike public and internal functions, an external function in the base contract is not available to be called from within the derived contract itself.

The only functions which aren’t inherited are those with private visibility.

Let me know if anything is unclear, or if you have any questions :slight_smile:

  1. A parent contract, or a contract which other contracts also known as child contracts derive from.

  2. All public and interal scoped functions are available for derived contracts.

  3. When a single contract acts as a base contract for other derived contracts.

1 Like

Nice answers @Adrian1 :ok_hand:

Yes … specifically speaking, hierarchical inheritance is when a single base contract is inherited by more than one (multiple) derived contracts. If the base contract is only inherited by one derived contract, then this is single inheritance.

  1. What is the base contract?
    The parent contract that child contract derive from.
  2. Which functions are available for derived contracts?
    Ones that are public or internal.
  3. What is hierarchical inheritance?
    Multiple child contracts derived from one parent contract.
1 Like
  1. This is the parent contract which means the child contracts underneath will inherit the base contract.

  2. Contains all public and internal scoped functions and state variables.

  3. This means more than one contract is inheriting from the parent contract. Instead of base contract, contract A = base, contract B = A.

1 Like
  1. The parent contract that child contracts are derived from.
  2. All public and internally scoped functions are available to child derived contracts. Not private scoped as those are specific to the contract in which they are defined.
  3. Multiple children derived contracts inherit from one base parent contract.
1 Like
  1. What is the base contract?

It is the parent contract in the context of inheritance.

  1. Which functions are available for derived contracts?

All public and internal scoped functions.

  1. What is hierarchical inheritance?

Hierarchical inheritance is the type of inheritance where multiple child contracts are derived from one parent contract.

1 Like