Inheritance Reading Assignment

  1. What is the base contract?
    The parent/base contract is the inherited contract.

  2. Which functions are available for derived contracts?
    All that are internal or public in the base contract are available for the derived contract.

  3. What is hierarchical inheritance?
    When a base contract can have multiple contracts derive from it.

1 Like

Hi @Thaddeus19,

A little bit of confusion here… but it may just be a difficulty in expressing the concepts in English (rather than not having understood them).

Anyway, just to clarify…

Yes :+1:

No… a derived contract inherits from its parent contract (the base contract).
(Note that we say derived contract, and not derivative contract).

No… it’s the opposite: the derived contract inherits the base contract’s public and internal functions and state variables.

Yes :+1: … but not just public and internal state variables, functions with public and internal visibility as well.

…just to clarify… the multiple contracts are the ones that inherit (not the parent contract) so we say that hierarchical inheritance is when a parent contract is inherited by multiple derived contracts.

I hope this clears up any confusion. :slightly_smiling_face:

2 Likes
  1. The parent contract

  2. Public and internal functions

  3. Multiple contracts derived from one base contract.

1 Like
  1. A base contract is the another name for the parent contract.
  2. All public and internal scoped functions and state variables are available to all derived contracts.
  3. Hierarchical inheritance is when a single contract is the base contract for multiple derived contracts.
1 Like
  1. A base contract is a contract that another contract is derived (inherits) from.
  2. All the base functions that are public and/or internal and all it’s own functions.
  3. It means that the derived contract gets all from its base contract which in turn gets all from its base contract.
1 Like

1. What is the base contract?
The base contract is the parent contract from which all the functions are inherited.

2. Which functions are available for derived contracts?
All the function in the contract and the parent contracts which are public and internal.

3. What is hierarchical inheritance?
Many contracts can inherit from a single base contract.

1 Like

Hi @chadrickm,

Q1 & 2 :ok_hand:

This is actually what is termed multi-level inheritance. According to the terminology, hierarchical inheritance is where more than one child contract is derived from the same parent contract.

2 Likes
  1. Base contract- parent contract- the contract that is inherited.
    2.All public and internal scoped functions and state variables are available to derived contracts.
  2. Hierarchical inheritance is when a single contract acts as a base contract for multiple derived contracts.
1 Like
  1. Base contract is the parent contract where children contract inherited from including state variables, functions
  2. All base functions are available for derived contracts
  3. Hierarchical inheritance is where a single contract acts as a base contract for multiple derived contracts.
1 Like

Hi @tung,

Just be careful with Q2:

This isn’t correct — only functions that have public or internal visibility are available for derived contracts.

1 Like

@jon_m, I did overlook the access modifier part.

Thank you for your time and helpful response.

1 Like
  1. What is the base contract?

Base contract is the contract that is inherited also known as 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 a type of inheritance where a single contract acts as a base contract for multiple derived contracts.

1 Like
  1. What is the base contract?

This is the parent contract that our contract inherits from.

  1. Which functions are available for derived contracts?

Ones declared in the base that have public, external or internal visibility.

  1. What is hierarchical inheritance?

Many derived contracts inherit from a single base contract using
single inheritance.

1 Like
  1. The base contract is the parent contract that is inherited by the child contract(s). So it is the most general contract in the sense that its public and internal variables and functions are common to all the contracts that are derived from it.

  2. In order for a function in a parent contract to be available in a derived child contract, it must be marked as ‘public’ or ‘internal’.

  3. We speak of ‘hierarchical inheritance’ when.a single base contract is inherited in parallel by several child contracts. The relevant syntax looks as follows:

    contract A {…}
    contract B_1 is contract A {…}

    contract B_n is contract A{…}

1 Like
  1. A base contract is one from which another contract can inherit variables and functions.

  2. Public and Internal functions.

  3. Hierarchical inheritance means that multiple contacts can be ‘children’ of a contract. So contract A can be a parent of contract B and contract B can then be a parent of contract C etc.

1 Like

Hi @sahowe1,

Q1 :+1:

Q2:

public & internal … YES :+1:
external… NO
Functions with external visibility are only available to other smart contracts which are also not derived. Take a look at this post for a coded example.

Q3:

Basically that’s correct, but I wouldn’t use the term single inheritance to describe the relationship between each derived contract and the parent. The fact that there are “brothers and sisters” means that it is no longer single inheritance.

Hi @JustinP,

Q1 & 2 :+1:

Q3…

Yes :+1: (that’s half the story)

What you’ve gone on to describe here is in fact multi-level inheritance.
The term hierarchical inheritance refers to a situation where two or more derived contracts inherit from a single parent contract e.g. where we have:

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

If we then add the following to this set up:

contract D is B {...}

We now also have the following multi-level inheritance:

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

I hope that’s clearer :slightly_smiling_face:

1 Like
  1. Base contract is parent contract.
  2. public and internal.
  3. Single contract is a base contract for multiple child contracts.
1 Like

Cool thanks for that! This course is a lot to take in!

1 Like

Yeh, it’s intense…but well worth the effort!
It’s important to pace yourself…not rush through the material, and follow things up with your own research, experimentation and use of this forum :slightly_smiling_face:

1 Like