Inheritance Reading Assignment

  1. What is the base contract?
    The base contract also known as the parent contract are the ones from which Child/Derived contracts inherit from .

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

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

1 Like

Nice answers @Nicco_Patel :ok_hand:

…and welcome to the forum! I hope you’ve been enjoying the course :slightly_smiling_face:

Just one comment about Q2 …

As well as state variables with public visibility, those with internal visibility are also available for derived contracts. The thing is that, unlike functions, state variables have internal visibility by default, and so including the internal keyword is optional. So, state variables defined without a visibility keyword, and those marked internal, are both available for derived contracts as state variables with internal visibility.

Just let me know if you have any questions.

  1. the parent
  2. public, internal
  3. 1 serves as parent for many
1 Like
  1. the base contract is the parent contract
  2. all public and internal scoped functions.
  3. multiple separate contracts from the same parent.
1 Like
  1. What is the base contract?
    This is the parent contract in a inheritance class relationship.
  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 inheritance relationship where a single contract acts as a base contract for multiple derived contracts.
1 Like

Nice answers @ryan_n :ok_hand:

Just to confirm … as with functions, it is the state variables defined in the base contract with public or internal visibility which are available for derived contracts — state variables marked private are not available.

Let me know if you have any questions.

1 Like

Hi! My answers:
1 A base contract is a contract whose code is inherited by another contract, a ‘child contract.’

2 All public-scoped and internal-scoped functions from parent contracts are available for derived contracts.

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

1 Like

Base (parent) contract is the contract where derived (child) contracts can inherit variables, functions modifiers and events from.

Derived contracts can inherit all the functions that are public and scoped internal from the base contract.

In hierarchial inheritance single smart contract is a base contract for multiple derived (child) contracts.

1 Like

Nice answers @Davelopa :ok_hand:

This is correct … and only functions with public and internal visibility in the base contract will be available to be called from within the derived contract itself.

So, functions with public and internal visibility are inherited, as well as any functions in the base contract with external visibility. However, unlike public and internal functions, inherited external functions won’t be available to be called from within the derived contract; when the derived contract is deployed, they will only be available to call externally e.g. from Remix, the front-end interface of a dapp, or an external (i.e. non-derived) contract.

The only functions which aren’t inherited are those with private visibility.

Let me know if you have any questions :slight_smile:

1 Like
  1. What is the base contract?
    The base contract or parent contract is the one being inherited from. It’s variables and functions are available to any subsequent child contracts.

  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?
    In hierarchical inheritance, a single contract acts as a base contract for multiple derived contracts.

1 Like

Nice answers @jrobbins :ok_hand:

But as you’ve clarified in your answer to Q2, it’s the functions and state variables in the base contract with public and internal visibility which are available to its derived contract(s). Functions and state variables with private visibility are not available.

A function in the base contract with external visibility will be inherited by a derived contract, but only to the extent that, when the derived contract is deployed, this function will be available to call externally. An external function in the base contract is not available to be called from within the derived contract itself.

Let me know if you have any questions.

1 Like
  1. The main parent.
  2. All the functions of the parent.
  3. More than one child, and they have same parent.

Hi @DanDD,

Q3 :ok_hand:

Q1 What is the base contract?

Just to be clear, a base contract is any parent contract that is inherited by a derived contract. Within an inheritance structure there can be more than one base contract e.g.

// Multi-level inheritance structure
contract A { ... }
contract B is A { ... }
contract C is B { ... }

In this multi-level inheritance structure:
C is a derived contract
A is a base contract… but not the only base contract …
B is both a derived contract (of A), and a base contract (to C)

Basically…
parent contract = base contract
child contract = derived contract
They are just alternative terms for the same thing.


Q2 Which functions are available for derived contracts

Not all of the functions in the parent contract are available. Functions with public or internal visibility are available for derived contracts, but not those with private visibility.

Let me know if anything is unclear, or if you have any questions :slight_smile:

  1. The contract has a parent known as the derived class and the parent contract.
  2. Public and internal scoped functions.
  3. Similar to simple inheritance. However, a single contract acts as a base contract for multiple derived contracts.
1 Like
  1. The base contract is the parent contract.
  2. All public and internal scoped functions and state variables are available to
  3. Hierarchical inheritance is is where a single contract acts as a base for multiple derived contracts.
1 Like

Hi @Kunanon_Jarat,

Q2 & Q3 :ok_hand:

Q1 What is the base contract?

There is actually an error in the article when it refers to class, here.
Contracts in Solidity operate in a similar way to classes in other object-oriented programming languages, and therefore the following are alternative names for the same thing:

parent contract = base contract = base class
child contract = derived contract = derived class

So, to correct your answer…

The child (or derived) contract inherits from a parent known as the base contract, the base class or the parent contract.

Let me know if you have any questions :slight_smile:

  1. What is the base contract?
    The base contract is 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?
    A single contract acts as a base contract for multiple derived contracts.
1 Like
  1. Parent contract, what all the child contract inherit from or “is”.

  2. Any public or internal functions

  3. A base contract for multiple contracts

1 Like
  1. A base contract is the one that another contract can inherit from.
  2. Derived contracts can use their parents public and internal functions.
  3. Hierarchical inheritance is when a parent contract has multiple children.
1 Like
  1. What is the base contract? - The contract from which you derived the child/derived contract

  2. Which functions are available for derived contracts? Public and Internal visibility marked functions.

  3. What is hierarchical inheritance? Multiple derived contracts using the same base contract. To have polymorphism you need to have poly (many) somethings that all have the same interface, but somewhat different behaviors (or why bother having poly anything?)

1 Like