Inheritance Reading Assignment

What is the base contract?
A base contract is the contract that provide its properties and functionalities as a template to its derived contracts. This is done through the Inheritance mechanism.

Which functions are available for derived contracts?
All the functions that are present in the base contract with the public and internal scope.

What is hierarchical inheritance?
An Inheritance relationship in which a single contract acts as a base contract for multiple derived contracts.

1 Like

The base contract is known as the parent contract, it is the contract that is inherited.

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

Hierarchical inheritance are a single contract that acts as a base contract for multiple derived contracts.

contract A {
........
 }

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

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

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

1.Parent contract
2.All public and internal scoped functions are available.
3.A hierarchical inheritance is similar to simple inheritance. In hierarchical inheritance, a single contract acts as a base contract for multiple derived contracts.

1 Like
  1. What is the base contract?

It is 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?

In hierarchical inheritance a single contract acts as a base contract for multiple derived contracts

1 Like

What is the base contract?

A single contract can act as a base contract for multiple derived contracts.

Which functions are available for derived contracts?

A derived contract can access all non-private members including internal methods and state variables.

What is hierarchical inheritance?

Look like a tree with top the base contract

1 Like

Hi @crypto_j55,

Firstly, apologies for the late feedback on this.

Q1 & Q2 :ok_hand:

Q3

That’s a great explanation of inheritance. However, the question is asking about a specific type of inheritance called hierarchical inheritance. The article described several different inheritance “structures”. Single inheritance is the most basic with just one child inheriting from a single parent. Instead of just one child, hierarchical inheritance is where multiple derived contracts inherit from a single parent.

Hi @seer,

Firstly, apologies for the late feedback on this.

Q2 & Q3 :ok_hand:

Q1

In your example B (not A) is the base contract (the parent). I think this is just a slip, because where you’ve used names instead of letters in Q3, you’ve identified the base contract ( ... is Vehicle ) perfectly.

Hi @kHarsh,

Q1 & Q3 :ok_hand:

Q2

Yes, obviously.

Only the parent contract’s functions and state variables with public and internal visibility are available for derived contracts, but not those with private or external visibility. The same is true for mappings.

Hi @Timmy,

Q1 & 2 :ok_hand:

Q3

Your definition is correct, but only the first 3 contract headers constitute hierarchical inheritance. I must admit it’s not all that clear from the article, but adding…
contract D is A,B,C { ......... }
makes it an example of multiple inheritance.
In fact, contract A can be omitted from this 4th contract header as follows:
contract D is B,C { ......... }
… because contract A is already inherited by B & C, and so A is implicity inherited by D via its inheritance of either B or C.

1 Like

Hi @gkassaras

This is in fact a definition of hierarchical inheritance (Q3). The definition uses the term base contract correctly, but it can also be any parent contract in any inheritance structure (e.g. there could just be one base/parent contract and one derived/child contract).

This is mostly correct. You are right that functions and state variables with private visibility are not inherited by derived contracts, and that those with internal visibility are (those with public visibility are inherited too). However, functions with external visibility are also not inherited (state variables cannot have external visibility).

  1. What is the base contract?
    A base contract is the inherited contract by a derived contract (which inherits from it).

  2. Which functions are available for derived contracts?
    All public and internal functions of the base contract is available to the derived contract.

  3. What is hierarchical inheritance?
    Hierarchical inheritance is where a single base contract is inherited by multiple derived contracts.

1 Like

Oh wauw, yeah, that must be a typo! :joy:

1 Like

The base contract is the parent contract in a parent/child contract relationship.

For derived contracts, all functions in any inherited contracts are available for use.

Hierarchical inheritance is when contracts are passed down to multiple child contracts.

1 Like
  1. A base contract is the parent contract (aka the contract that a child contract is derived from).
  2. Functions from the parent contract are available for derived contracts.
  3. Hierarchical inheritance refers to a situation where a single contract acts as a base contract for more than one child contract or inherited contract.
1 Like

Reading Assignment: Inheritance (Answers)

  1. A Parent-contract
  2. Internal Scope Functions.
  3. Single contract acts as a base contract for multiple derived contracts.
1 Like
  1. The parent contract is known as a base contract.
  2. Variables, functions, modifiers, and events of base contracts into the derived class.
  3. 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- The base contract is the parent contract

2- Since derived contracts are child contracts. Its functions are therefore derived from the parent(base) contract. So what is available in the parent(base) contract is what will be available for the child(derived) contract.

3- Hierarchical Inheritance is the relationship between a parent(base) and child(derived) contract similar to how simple inheritance works accept for the child(derived) contracts are formed in a way where there can be multiple child(derived) contracts to a single parent(base) contract.

DUUKAA!!!

1 Like
  1. What is the base contract?
    The 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
    It is when a single contract acts as the base for multiple derived contracts

1 Like
  1. What is the base contract?
    The parent of an 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 a base contract for multiple derived contracts.
1 Like
  1. The base contract is the parent contract.
  2. The public and internal functions are available for derived contracts.
  3. When a single contract acts as a base contract for multiple derived contracts.
1 Like