Inheritance Reading Assignment

  1. The base contract (or the parent contract) is the contract that the derived (or child) contract inherits attributes from.

  2. Public and internal scoped functions can be used by derived contracts.

  3. In hierarchical inheritance, multiple contracts are derived from the same base contract.

1 Like
  1. The base contract is the parent contract or original contract that child contracts will derive from.
  2. All the public functions in the parent contract will be available in the derived contract.
  3. Hierarchical inheritance is when multiple contracts derive from a single parent contract.
1 Like
  1. The parent contract is known as a base contract .Inheritance is mostly about code reusability
  2. There is a is-a relationship between base and derived contracts and all public and internal scoped
    functions and state variables are available to derived contracts.
  3. A single contract acts as a base contract for multiple derived contracts.
1 Like
  1. The base contract is the original or parent contract.
  2. public and internal functions are available for derived contracts.
  3. Hierarchical inheritance means multiple derived contracts are inheriting from a single base contract.
1 Like

1.The contract that is inherited also known as parent contract.
2. 1. All the functions in the parent contract are available for the child contracts.
3. Hierarchical inheritance is like having multiple children. They come from the same parent but are different from one another.

1 Like
  1. What is the base contract?

Base contract is a parent contract, that is inherited by
it’s child contracts.

  1. Which functions are available for derived contracts?

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

  1. What is hierarchical inheritance?

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

1 Like
  1. What is the base contract?
  • the parent contract that does not inherit from any other contract.
  1. Which functions are available for derived contracts?
  • functions that visibility specifiers public or internal.
  1. What is hierarchical inheritance?
  • for instance the parent contract also have a parent contract
1 Like

Hi @hannezzon,

Yes :+1:

Not necessarily…
… where there is multi-level inheritance, a contract could be BOTH
(i) the base/parent of one contract (its derived contract)
AND
(ii) the child/derived contract of another contract (its inherited contract).

Correct :ok_hand:

No … what you are describing is multi-level inheritance — the contract set-up I have also described above.
Hierarchical inheritance is where more than one child contract is derived from the same parent contract.

2 Likes

1.What is the base contract?
The contract from where other contracts inherit the features called base contract.
2.Which functions are available for derived contracts?
Public and internal properties of a base contract are available to the derived contract.
3.What is hierarchical inheritance?
It is when a single contract acts as a base contract for multiple derived contracts.

1 Like
  1. What is the base contract?
  • Also known as the parent contract, it is a contract that is inherited by other contracts (child contracts, derived contracts). That means, if we have a base contract A and it is inherited by a derived contract B, B will contain all the functionality that A has, plus its own.
    We declare it with the is keyword:
    Contract A {
    …(base functionality)…
    }
    Contract B is A {
    …(added functionality)…
    }
  1. Which functions are available for derived contracts?
  • Public and internal functions and variables.
  1. What is hierarchical inheritance?
  • When several derived contracts inherit the same base contract, it is called hierarchical inheritance.
  • One contract can also inherit several base contracts, and that is multiple inheritance. However, I am confused about the declaration here:

Why do we have to declare that D inherits A, if B and C already inherit A?

1 Like

Hi @cryptocoder,

Q1 & Q3 :ok_hand:

Just to clarify…
…“Public and internal functions and state variables of a base contract are available to the derived contract.”

1 Like

Hi @MarcisB,

Your answer to Q1 is correct, except that:

B might not contain all the functionality that A has.
It will inherit any modifiers, events, public and internal functions, and public and internal state variables.
But it won’t inherit any private or external functions, or any private or external state variables.


Q3

You are absolutely right — there is no need to explicitly declare that D inherits A in the code, as it automatically inherits A via B and C. The following is therefore sufficient:

contract D is B, C {...}

Although,   contract D is A, B, C {...}   is not wrong — just unnecessary.

2 Likes

1)Base contract is also known as parent contract.
2)all public and internal scoped functions and state variables are available to derived contracts.
3)a single contract acts as a base contract for multiple derived contracts.

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

  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.

1 Like
  1. a base contract is the parent contract.
  2. all public and internal functions are available to derived contracts.
  3. it’s when a parent contract is a parent to multiple child contracts.
1 Like
  1. What is the base contract?

A base contract is the parent contract that a child contract derives from.

  1. Which functions are available for derived contracts?

A derived contract can access all of the public and internal functions in the parent contracts it derives from.

  1. What is hierarchical inheritance?

Hierarchical inheritance is when a base contract is the parent of multiple child contracts.

1 Like
  1. the parent contract or contract that another contract gets its inheritance from.
  2. variables, functions, modifiers, and events
  3. a single contract acts as a base contract for multiple derived contracts
1 Like
  1. What is the base contract?
    Parent contract (which is inherited) 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?
    Hierarchical inheritance is similar to simple inheritance except that a single contract acts as a base contract for multiple derived contracts.
1 Like

Hi @Proniss,

Q1 & 3 :ok_hand:

Q2 Which functions are available for derived contracts?

You are right that all modifiers and events are inherited by derived contracts :+1:
But not necessarily all state variables and functions are available for derived contracts. It depends on their visibility — you need to find out which visibility types they need.

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

1 Like