Inheritance Reading Assignment

  1. base concract is a parent contract
  2. all
  3. single contract acts as a base contract for multiple derived contracts
2 Likes

No… not all functions…those with public or internal visibility are available for derived contracts. Functions with private or external visibility are not available.

  1. What is the base contract?
    The contract that is inherited called parent contract, also 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- It’s a contract that has a child contract
2- All public and internal (no external)
3- Hierarchical inheritance refers to a contract that is the base for several children contracts

1 Like

Nice answers @raul782 :ok_hand:

Yes, that’s correct… and as well as external functions, private functions are also not available.

1 Like

1: The base contract is the root or parent contract of the rest.

2: public and internal functions and state variables are available.

3: A single base contract that has (child) contracts under it derived from it.

1 Like

Yes… more than just one child contract.

1 Like
  1. What is the base contract?
    Foundation contract that acts as a base by providing
    necessary variables, functions, modifiers, and events.
    Solidity copies the base contract into the derived contract and
    a single contract is created with the inheritance. A single
    address is generated that is shared between the two
    contracts.

  2. Which functions are available for derived contracts?
    Modifiers such as external, public, internal and private affect the visibility of state variables within the contract in which they are defined, inheriting child contracts or outside contracts.

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

2 Likes
  1. The base contract is the parent contract.
  2. All the public and internal scoped contracts of the base contract are available for derived contracts.
  3. In hierarchical inheritance a single contract acts as the base contract for multiple derived contracts.
2 Likes
  1. The base contract also called the parent contract is the contract that other ā€œchildā€ contracts inherit or derive code from.
  2. The public and internal functions created in the base contract are available for a derived contract.
  3. In hierarchical inheritance a single contract acts as the base contract for multiple derived contracts.
2 Likes

Thanks Filip for putting your code in Githuib!! Huge help!!

1 Like

Hi @dani88,

Q1 & 3 :ok_hand:

These 4 visibility types are used to define the visibility of both state variables and functions.
Not all of the functions or state variables in a parent/base contract are inherited by (available to) derived/child contracts. Those with public or internal visibility are available. But those with external or private visibility are not available.

1 Like

Nice answers @PhilD99 :ok_hand:

I’m sure it was just a slip… but this should be:ā€‚ā€œAll the public and internal scoped functionsā€¦ā€ (not contracts).

So, what is the difference between external and private?

1 Like

Hi @dani88,

private visibility: only accessible from within the same contract i.e not accessible from derived contracts, external contracts, or from external services.

external visibility: accessible from external contracts and external services, but not accessible from within the same contract or from any derived contracts (i.e. the opposite of internal visibility)

  1. What is the base contract?

The base contract is also known as the parent contract.

  1. Which functions are available for derived contracts?

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

  1. What is hierarchical inheritance?

Hierarchial inheritance is when a single contract acts as a base contract for multiple derived contracts.

2 Likes
  1. What is the base contract?

It is the contract where all the methods & variables are defined. Further they can be viewed, used or modified by the other classes based on access modifiers specified in the base contract.

  1. Which functions are available for derived contracts?

Public functions : Available to all contracts includes derived contract.
Internal functions : Available within the contract only & contracts derived from it.
Private functions : Not available to derived contract.

  1. What is hierarchical inheritance?

It’s like a simple inheritance but the only difference is that it can derived by the multiple
contracts.

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

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

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

2 Likes
  1. parent contract
  2. polymorphism
  3. base contract acts as a base for multiple contracts

Hi @Bhushan_Pawar,

Q2 & 3 :ok_hand:

Yes… it is where more than one child contract is derived from the same parent contract.

I think you’ve got a bit confused here, and overcomplicated things…
The base contract is the parent contract , the contract which is inherited by the child (or derived ) contract .

No… not all the functions and variables. A derived contract usually contains most of the functions and variables. It also inherits the public and internal functions and variables in its parent contract(s), and which are also available to the derived contract when it is deployed.

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