Inheritance Reading Assignment

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

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

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

1 Like

1.What is the base contract?
Is a parent contract known as a derived class to child contract.

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

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

1 Like
  1. Its the original parent contract
  2. Inheritance is about code-reusability, so all public and internal scoped functions
  3. Hierarchical inheritance is one parent contract as base for multiple derived contracts
1 Like

Nice answers @Cero :ok_hand:

Just to clarify a few things…

As with functions, both public and internal state variables in the base contract are inherited by the derived contract.

Let me know if you have any questions :slight_smile:

Nice answers @ZED91 :ok_hand:

Just to confirm…

Q1  What is the base contract?

It’s any contract inherited by a derived/child contract i.e. any parent contract, not just the ā€œoriginalā€.

1 Like

Thank You :slight_smile:

1 Like
  1. What is the base contract?

The contract that is inherited is called the parent contract or Base Contract.

  1. Which functions are available for derived contracts?

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

  1. What is hierarchical inheritance?

A single contract acts as a base contract for multiple derived contracts.

1 Like

1. What is the base contract?
The base contract is the one whose functions and features are inherited by a child contract.

2. Which functions are available for derived contracts?
Derived contracts can access all publicly and internally scoped functions and state variables.

3. What is hierarchical inheritance?
When a parent contract has been inherited by more than one child contract, it is hierarchical inheritance.

Also a little feedback, medium is not accessible in many countries without a VPN.

Here is an alternate link, to geeks for geeks, which served me well.

2 Likes

Nice answers @Jackthelad :ok_hand:
… and thanks for the feedback about the availability of the Medium article.

Just to confirm … as with functions, it is the public and internal state variables in the base contract which are inherited by the derived contract. State variables with private visibility are not inherited.

What do you mean by ā€œinternal methodsā€? As well as public and internal functions, and public and internal state variables (including mappings and arrays), all modifiers and events are also inherited.

Let me know if you have any questions :slight_smile:

Thanks again for the constructive comment.

You got me to go back and look into methods, I had learnt a little about them in the JavaScript course but my recollection was wrong. I would have continued for a while with my incorrect understanding had you not commented.

A method is a function related to an object and is a type of modifier. Would this be a reasonable definition?

So if the public/internal function or state variables are inherited, the modifiers connected to them are automatically inherited.

My addition of them as something separate was redundant.

1 Like
  1. The base contract is a smart contract with other contracts that inherit from it, so the contracts are related in a ā€˜parent-child’ relationship.

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

  3. Hierarchical inheritance is where a number of contracts all inherit from one single parent contract.

1 Like

Hey Jack,

Glad the comment was helpful.

I think this is probably the most helpful way to understand what a method is.

Firstly though, we do need to recognise that some of these terms can be used to mean slightly different things in different programming languages. That’s another reason why I asked you what you meant by the term.

That being said, in JavaScript a method is as described in this quote from your post, above. As you know, objects have properties, and a method is a type of property that is a function. I think that’s all you need to know about methods really. I can see how we could also understand methods to be…

… but, then we get into what exactly a modifier is, and with Solidity that could make things more confusing, as you probably already have a clear understanding of what a modifier is.

The Solidity documentation doesn’t actually use the term method. But the same type of function does exist in Solidity e.g.

transfer( )
// in
msg.sender.transfer(amount);

In Solidity this is termed a member, and transfer is a member of the payable address type. Below is a link to a list of the Members of Address Types in the documentation. You may see some others that you recognise:

https://docs.soliditylang.org/en/latest/units-and-global-variables.html#members-of-address-types

Address values are objects in Solidity and, as an object, an address contains different properties. In Solidity, the term member is mostly used in the documentation, but you will also see the term property or attribute used by developers to mean the same thing. One of these ā€œaddress propertiesā€ is balance, and another is the function transfer( ) . Solidity developers also use the term method for these types of functions. Personally, I like the term method for these types of member, because I also know JavaScript, and in Solidity they are called on an object in the same way — using dot notation.

Correct… and that must be why all modifiers are inherited, otherwise this could create an issue with any public or internal functions that have a modifier in their function header.
Members are predefined in Solidity, and so they are automatically available to us within the environment. As we don’t define them within our contract in the same way we define modifiers and functions, inheritance is therefore not an issue that affects members that are functions (i.e. methods), and they will be automatically available within the public/internal functions or state variables which are inherited by a derived contract.

I hope that makes sense :sweat_smile:

Just let me know if you have any further questions.

1 Like
  1. The base contract is the parent contract.
  2. All public & internal scoped functions are available for derived contracts.
  3. A hierarchical inheritance is when there’s a parent/base contract that has multiple child contracts.
1 Like
  1. The Parent contract
  2. All state variables, and functions with public or internal visibility
  3. When a single contract acts as a parent for multiple child contracts
1 Like
  1. What is the base contract?
    The base contract is the parent contract, the one from which other contracts inherit.

  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 is when a parent contract (base) has more than one child contract (derived).

1 Like

Hi @DHash,

Q1 & Q3  :ok_hand:

Q2  Which functions are available for derived contracts?

In terms of functions, that’s correct… but not all state variables are available. As with functions, it is the public and internal state variables in the base contract which are inherited by the derived contract. State variables with private visibility are not inherited.

Let me know if you have any questions.

1. What is the base contract? The parent contract.
2. Which functions are available for derived contracts? All public and internal scoped functions (and state variables).
3. What is hierarchical inheritance? Where a single contract acts as a base contract for multiple derived contracts.

1 Like
  1. What is the base contract?
    The inherited contract is called the base contract

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

  3. What is hierarchical inheritance?
    This is the type of inheritance in which a single contract acts as a base contract for multiple derived contracts.

1 Like

Nice answers @adykor :ok_hand:
… and welcome to the forum!

Just to confirm … as with functions, it is the public and internal state variables in the base contract which are inherited by the derived contract. State variables with private visibility are not available.

Don’t forget to post your solutions for the first 3 assignments for this course as well (Data Location, Events and Transfer).

Just let me know if you have any questions.

Nice answers @Precious :ok_hand:

Don’t forget to post your solution to the Transfer assignment as well.