Inheritance Reading Assignment

  1. The parent contract is known as a base contract.
  2. Function polymorphism
  3. Hierarchical inheritance is similar to simple inheritance
  1. Base contract is also known as parent contract.
  2. Public and internal scoped functions are available to derived contracts.
  3. Hierarchical inheritance is when single contract acts as a base contract for multiple derived contracts.
1 Like
  1. A base contract is the parent contract from which a child inherits methods and state variables.
  2. Methods with public and internal visibility modifiers are available to child contracts.
  3. Hierarchical inheritance is an inheritance structure in which a single contract can serve as a parent to many contracts.
1 Like

Hi @Yavuz_Gedik,

Q1 :+1:

No…

Functions with public or internal visibility are available for derived contracts.

No…

Hierarchical inheritance is where more than one child contract is derived from the same parent contract.

Simple inheritance is not a term used to describe inheritance. Single inheritance is where a single child contract is derived from a parent contract.

  1. What is the base contract?
    The parent contract is known as a base contract.

  2. Which functions are available for derived contracts?
    Public and internal scoped functions and state variables are available to derived contracts.

  3. What is hierarchical inheritance?
    It acts as a base contract for multiple derived contracts.

1 Like

1 - What is the base contract?

The contract that is inherited is called the parent contract, also known as the 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 a single contract acting as a base contract for multiple derived contracts.

1 Like
  1. Its the “parent” contract, or the the one from which all other contracts are derived.
  2. All public and internal scoped contracts. Not really sure what “scoped” means but I’m assuming … within the scope of the base contract?
  3. It’s inheritance from a base contract into multiple derived contracts. These derived contracts can also interact, as far as I understand, and even further derived contracts can be made from these, known as multiple inheritance, apparently.
1 Like

Hi @Nile,

Q1 & 3 :ok_hand:


Q2  Which functions are available for derived contracts?

functions (and state variables) not contracts. If a contract is inherited, its functions and state variables that are marked public or internal are all inherited by the derived contract(s).

No…

Scope basically means visibility. The scope of a function or variable defines where it can be accessed from (i.e. invoked/executed or referenced). So, when we mark a function with public visibility, its scope includes: within the same contract, within all other contracts (whether derived or not), and external services (e.g. Remix). This is the least restrictive scope (or visibility).

In contrast, functions marked private, have the most restrictive scope/visibility: they can only be accessed from within the same contract they’ve been defined in, and so cannot be inherited.

Functions marked internal can be accessed from within the same contract and all its derived contracts. In other words their scope includes: the same contract and that contract’s derived contracts, but not any other contracts or external services. So, this type of function can also be inherited (along with those marked public).

I hope that makes things clearer. But do let us know if you have any further questions.

Thanks! That really clears it up.

1 Like
  1. The base contract contract is the contracts that is inherited also called parent 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. The contract from which other contracts inherit, or parent contract
  2. Public/ internal scoped functions and also state variables are available to derived contracts
  3. It is when a contract has several derived contracts instead of only one
1 Like
  1. What is the base contract?
    Parent contract of child contracts of derived class is known as a base contract.

  2. Which functions are available for derived contracts?
    There is a relationship between base and derived contracts such that 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, however, a hierarchical inheritance contract acts as a base contract for multiple derived contracts.

1 Like

1. What is the base contract?
The base contract would be considered the parent contract. The contract in which others inherit from.

2. Which functions are available for derived contracts?
All the public and internal functions are available for derived contracts.

3. What is hierarchical inheritance?
A single (parent) contract acts as a base contract for multiple derived contracts.

2 Likes
  1. The base contract is the contract that is inherited. Its is the parent contract in other word.
  2. All functions for his parent contract. And the ones from other contracts if his base contract is a derived contract it self. [edit] And state variable**
  3. Its is when multiple contracts are derived from one base contract.
1 Like
  1. The base contract is the parent contract of the derived class.

  2. The functions available for derived contracts are all public and internal scoped functions and state variables.

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

1 Like

Hi @guillaume_M-D,

Q1 & 3 :ok_hand:

No, I think you’re confused here…
… Not all functions and state variables are inherited from parent contracts and available for derived contracts — just the ones with public or internal visibility .

1 Like
  1. What is the base contract?
    the top level parent contract from which all the children inherit.

  2. Which functions are available for derived contracts?
    all public and internal functions;

  3. What is hierarchical inheritance?
    parent with two childs that inherit exactly the same.

1 Like

Totally right, I omitted this parts sorry.
To my understanding, it will inherit everything that is no set as private. Hence why I said everything… Because to stop something from being inherited you need to specify it by making the element private. It is by default visible/public to child contracts.

1 Like

I actually cant remember if an element that doesn’t have a visibility indicated is public or private by default.
[edit] Yes the default visibility is public. https://solidity.readthedocs.io/en/v0.5.3/contracts.html#visibility-and-getters.
Btw, I’m sharing my thought process, not defending it :wink: :smiley:
Thanks again good sir

1 Like

Hi @CeesQ,

…could also be more than two derived contracts. Hierarchical inheritance is where more than one child contract is derived from the same parent contract.