Inheritance Reading Assignment

  1. What is the base contract? The base contract is the Parent contract of a Derived Class contract; which these in turn, inherit variables, functions, modifiers and events of the base contracts.

  2. Which functions are available for derived contracts? Single inheritance, Multi-level inheritance, Hierarchical inheritance and Multiple inheritance.

  3. What is hierarchical inheritance? When a single contract acts as a base contracts for multiple derived contracts. A is the parent of both B and C.

1 Like

Nice answers @Haysoose :ok_hand:

Just a comment about your answer to question 1 …

This is partly correct. A base contract is any parent contract. So in the following example of multi-level inheritance, contract B is both C’s parent/base contract, and at the same time it is a child contract of A

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

Hi @bjamRez,

Q1 & Q3 :ok_hand:

Single inheritance, multi-level inheritance, hierarchical inheritance and multiple inheritance are all types of inheritance structure.
Whatever the inheritance structure, the functions that are inherited from a parent contract by one or more of its derived contracts are those with public or internal visibility. Private and external functions are not available to derived contracts. The same is true for state variables and mappings. But all events and modifiers are inherited.

1 Like
  1. A base contract is known as the parent contract that is inherited.
  2. All public and internal scoped functions and state variables are available to derived contracts.
  3. Hierarchical inheritance is when a single contract acts as a base contract for multiple derived contracts. An example of this is:
(Base Contract)
contract A {
.................
}

(Derived Contract)
contract B is A {
.................
}

(Derived Contract)
contract C is A {
.................
}
1 Like

Thank you for the clarification!

1 Like
  1. What is the base contract?
    “Contract has a parent known as the derived class and the parent contract is known as a 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?
    a single contract acts as a base contract for multiple derived contracts.
1 Like
  1. The parent contract.
  2. Both public and internal scoped functions and state variables.
  3. When a single contract acts as a base contract for multiple derived contracts.
1 Like
  1. What is the base contract?

Base contract is the parent contract.

  1. Which functions are available for derived contracts?

Variables, functions, modifiers and events of base contracts are available in the derived contracts

  1. What is hierarchical inheritance?

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

1 Like
  1. The base contract (parent contract) is the contract that is inherited from the child contract (derived class). In this way multiple contracts that are related to each other through parent-child relationships, are defined, through inheritance.

  2. All (implemented) functions are available for derived contracts. Besides functions inherited are also the variables, modifies and events of base contracts into the derived class.

  3. Hierachical inheritance is the definition of a single contract acting as a base contract for multiple derived contracts.

1 Like

What is the base contract?
In the parent-child relationship inheritance, it is the very first parent contract.

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

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

1 Like

Hi @rallen221,

Q2 & Q3 :ok_hand:

This is the correct answer.

This is incorrect, and is an error in the article. The derived contract can also be called the derived class. Its parent (or base) contract, can also be called the parent (or base) class.

Hi @mwonder,

Q1 & Q3 :ok_hand:

All modifiers and events in a base contract are inherited by its derived contracts, yes, but not all state variables and functions are available. Public and internal functions are available for derived contracts, but not those with private or external visibility. The same is true for state variables and mappings.

Hi @makinitnow,

Q3 :ok_hand:


Q1

This is correct.

The base contract is inherited BY not FROM the child contract.


Q2

All modifiers and events in a base contract are inherited by its derived contract(s), yes, but not all state variables and functions are available. Public and internal functions are available for derived contracts, but not those with private or external visibility. The same is true for state variables and mappings.

1 Like

Nice answers @evasilev :ok_hand:

Just a comment about your answer to question 1 …

This is partly correct. A base contract is any parent contract. So in the following example of multi-level inheritance, contract B is both C’s parent/base contract, and at the same time it is a child contract of A

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

Hi @jon_m,

In this case I have a question: what is contract A to contract C? Is it correct to say that both A and B are parents to C or is it just B? And in a multi-level inheritance we have multiple base contracts?

1 Like
  1. A contract that is inherited is called the base contract or parent contract.

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

  3. At first, hierarchical inheritance is similiar to single inheritance which helps in inheriting the variables, functions, modifiers, and events of base contracts into the derived class. But a single contract acts as a base contract for multiple derived contracts.

1 Like

Very good question @evasilev!

I think this is correct, because if we think about what functionality is available to contract C when it is deployed, the answer is: it’s own + inherited functionality from both A and B. Inherited functionality comes from parent contracts (also called base contracts). Complex inheritance structures can be made up of several non-exclusive, or overlapping, parent/child relationships.

1 Like
  1. A Base contract is a parent contract for a child contract. :slight_smile:
  2. All public and internal functions.
  3. Hierarchical inheritance is when a single contract acts as a base contract for multiple derived contracts.
1 Like

Hi Jon,
Thanks again for the detailed explanation & correction. From was a typo.

1 Like
  1. Base contract is the contract that is inherited. Or can also be called the parent contract in a Parent-Child relationship of contracts. In addition, the child contract/s is/are also called derived contract/s.

  2. All public and internal scoped functions and state variables of the base contract are available to derived contracts.

  3. In hierarchical inheritance, a single contract acts as a base contract for multiple derived contracts. Please check image below illustrating hierarchical inheritance, wherein Contract A is the base contract (parent) and Contracts B & C are the derived contracts (children).

1 Like