Inheritance Reading Assignment

Don’t worry, there’s a lot to remember :wink:

1 Like

1. What is the base contract? The base contract, which is also known as the parent contract, is the contract from which information is inherited.

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? When more than one contracts are derived from a single base contract, such inheritance is known as hierarchical Inheritance.

1 Like
1. What is the base contract?

The parent contract is known as the base contract.

2. Which functions are available for derived contracts?

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

3. What is hierarchical inheritance?

Hierarchical inheritance consists of a single contract that acts as a base contract for multiple derived contracts.
1 Like
  1. What is the base contract?

The base contract is the one used as parent.

  1. Which functions are available for derived contracts?

All public and internal functions are available for derived contracts. “external” functions not only are available to the derived contracts, they can be called only by the derived contracts (and can’t be called in the same base class).

  1. What is hierarchical inheritance?

Hierarchical inheritance means that different contracts can inherit from the same base contract.

  1. What is the base contract?
  • The parent contract is the base contract
  1. Which functions are available for derived contracts?
  • Public and internal scoped functions and state variables are available to derived contracts.
  1. What is hierarchical inheritance?
  • Hierarchical inheritance is a single contract that acts as a base contract for multiple derived contracts.
1 Like
  1. Parent contract, it is the contract that is inherited by another
  2. All functions that are defined by using public scope, internal scope, and state variables.
  3. A type of contract inheritance where the parent contract has multiple child contracts derived from it
1 Like
  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 functions derived from the base contract.

3.What is hierarchical inheritance?
When the are multiple contracts derived from a single base contract.

1 Like

Hi @firepol!
Sorry for the delay in reviewing these answers.

Q1 & 3 :ok_hand:

Yes :+1:

I’m pretty sure that functions with external visibility are only available to any other smart contract (not just to derived ones). In fact I’m not even sure if derived contracts can access them. As I’m not sure, I’m asking @gabba to confirm this with you.

1 Like

Actually external methods can be call by an other contract but CAN’T be called by in the same contract or by a derived contract . An example bellow

pragma solidity 0.5.12;

contract A{
  function test(uint256 _test) external payable;
}

contract B{
    A public instance;    

    constructor(address _contractAddr) public {
        instance = A(_contractAddr);
    }
    
    function callTest() public{
        instance.test(4); // OK
    }
    
    function callTestExt() external returns(uint256){
        instance.test(5);  // OK
    }

    function callTestExtInternal() public{
        callTestExt(); // Doesn't work no visibility
    }

}

contract C is B{
    
    function testC()public{
        callTest();  // OK
    }
    
    function testCExt()public{
        callTestExt(); // Doesn't work no visibility
    }
}
1 Like
  1. The base contract is the type of contract that is inherited by another contract.
  2. All public and internal scoped functions.
  3. It is an inheritance where a single contract acts as a base contract for multiple derived contracts.
1 Like

Thanks for the clarification, now I understand external better!

1 Like

1. What is the base contract?
The base contract is the parent contract.

2. Which functions are available for derived contracts?
Derived contracts, or child contracts inherit functions state, public,and internal.

3. What is hierarchical inheritance?
Basically, it works as a standard hierarchy. It starts with a base contract, and then falls down to derived contracts. The derived contracts inherit from the base.

1 Like
  1. The base contract is the parent contract from whom another contract inherits.
  2. All public and internal functions and state variables are available to derived contracts.
  3. Hierarchical inheritance describes the situation when multiple contracts inherit from the same base contract.
1 Like

1. What is the base contract?
Base contract is the parent contract and the base contract is inherited by other contracts.

2. Which functions are available for derived contracts?
Functions with the visibility public, external and internal are inherited by other contracts.

3. What is hierarchical inheritance?
Hierarchical inheritance is where the multiple contracts inherits the functionality of the base contract.

1 Like

Hi @Jian_Hao_Wei,

Everything is correct except one small thing…

Only functions with public and internal visibility are inherited by derived contracts. Functions with external visibility can only be accessed by other contracts which are not derived from the contract with the function marked external.
Have a look at this post.

I hope that makes things clear.

1 Like
  1. A base contract is a parent contract from which child(ren) contract(s) inherit properties.

  2. All public and internal functions are available to classes derived from parent contracts.

  3. Using hierachical inheritance, a base contracts act as the “parent” to multiple children contracts.

1 Like
  1. A contract which is being extended by inheritance will become the base contract or parent contract of the derived contract. In Solidity, the bytecode of the base contract will be copied into the extending contract.

  2. The derived contract has access to all public and internal functions of the base contract.

  3. Hierarchical inheritance is when several contracts are derived from the same base contract.

1 Like
  1. What is the base contract?
    The contract from where derived ones will inherit.

  2. Which functions are available for derived contracts?
    State variables and all public and internal scoped functions.

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

1 Like

What is the base contract?
The base contract is also known as the parent or derivative contract and it inherits its functions and state variables.

What functions are available for derivative contracts?
Public and / or internal variables are available.

What is hierarchical inheritance?
It is when a parent contract is inherited for multiple contracts.

1 Like

Hi @dAnijboned,

… just to clarify…state variables also need to have public or internal visibility to be inherited (not all state variables).

2 Likes