Inheritance Reading Assignment

“other classes” means derived contracts. I used oops tern that too in wrong way.
I think “used or modified by the other classes” can be replaced by " inherited by derived contracts." Hope that serve the purpose.

In second statement “It is the contract where all the methods & variables are defined.”
I shouldn’t have used “all” the methods & variables. Yep you are right it should be “most” :slight_smile:

1 Like

Hi @Andrewg,

Q1 :ok_hand:

No…
Functions in the parent contract which have public or internalvisibility are available for derived contracts.

Kind of…
Hierarchical inheritance is where more than one child contract is derived from the same parent/base contract.

Let us know if anything is unclear, or if you have any questions, so we can help you :slight_smile:

Hi @Bhushan_Pawar,

Yes… that makes sense now :ok_hand: Thanks for clarifying :slight_smile:

We’re describing the base contract, so it should be… “It is the contract where some of the functions and state variables available to its derived contract(s) are defined.”
Most of the functions and state variables are usually in the derived contract, as that’s the contract which is actually deployed.

So, here, do you mean:
…“they (base contracts) can be inherited by derived contracts by adding specific code/syntax to the header of the derived contract”…?
By “access modifiers” do you mean the   contract A is B { ... }  syntax we use to establish the inheritance relationship?

  1. What is the base contract?
    The contract(s) that the derived contract inherits from.
  2. Which functions are available for derived contracts?
    Private and Internal. External functions can be called using this.f()
  3. What is hierarchical inheritance?
    Two or more contracts inherit from the same base contract
1 Like
  1. The parent contract which is the derived class.
  2. Public, internal functions, and state variables.
  3. When a single contract acts as the base contract for multiple derived contracts.
2 Likes

Hi @decrypter,

Q1 & 3 :ok_hand:

Maybe this question wasn’t clear about what it was getting at. Basically, it’s asking which functions in the parent/base contract are inherited by the derived contract (available to it when it is deployed).
Functions in the parent contract with public or internal visibility are inherited by derived contracts. But those marked private or external are not inherited. Only functions marked private within the derived contract itself will be available for that same derived contract.

Nice answers @santoretech :ok_hand:

Just a couple of clarifications…

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, if the article hadn’t misled you, your answer would be: “The parent contract (or parent class).”

As with functions, state variables also need to have public or internal visibility to be inherited.

1 Like

1. What is the base contract?
A Base contract is also known as a parent contract when two or more contracts are using inheritance. The base contract or parent contract contains data that is inherited by the child contracts. Inheritance allows you to define multiple contracts and relate them to each other and be able to have efficient code reusability.

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

What is hierarchical inheritance?
Hierarchical inheritance is when a single contract acts as a parent contract for multiple children contracts, while the children contractions are not related to each other in the way that leveled inheritance occurs.

2 Likes

Of course I meant Public and internal. Thinking Public while typing private… :grimacing:

1 Like
  1. What is the base contract?

The parent contract

  1. Which functions are available for derived contracts?

Public, internal and state variables are available for derived contracts.

  1. What is hierarchical inheritance?

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

1 Like

Nice answers @Alex_Carr :ok_hand:

Just to confirm… as with functions, state variables also need to have public or internal visibility to be inherited i.e. state variables marked private, and functions with private or external visibility, are not inherited.

  1. It Is known as the parent contract to the child contract
  2. external , public , internal , and private
  3. Hierarchical inheritance** is a kind of inheritance where more than one class is inherited from a single parent or base class. Especially those features which are common in the parent class is also common with the base class.

Hi @jahh,

Q1 :ok_hand:

No… functions in the parent contract with public and internal visibility are inherited, but not those marked external or private.

I think you probably mean the opposite to what you’ve actually written…
With hierarchical inheritance, more than one derived class (or child contract) inherits from a single parent contract (or base class).

I’m not sure what you mean here… the parent contract and the base class are the same thing:

Whatever the overall inheritance structure, the “rules” of inheritance are always the same between each parent/child pair within that structure.

Hi Jon, Thanks for the feed back , that means a lot to me

1 Like

You’re very welcome @jahh! I’m glad you find it helpful :muscle:

1. What is the base contract? Is the parent contract for all sons derived of base.
2. Which functions are available for derived contracts? All the public functions of the parent(s)
3. What is hierarchical inheritance? Its the inheritance that the contract can access from parent or parents A->B A->B/C

Hi @Raf.PV7,

Q1 :ok_hand:

Yes… but also functions in the parent contract with internal visibility.

No… hierarchical inheritance is where more than one child contract inherits from the same, single parent contract e.g.

contract A { ... }
contract B is A { ... }
contract C is A { ... }

In contrast, I think you have described both…

1) Single inheritance, which is where a single child contract inherits from a single parent contract  i.e.

contract A { ... }
contract B is A { ... }

and

2) Multiple inheritance, which is where the same, single child contract inherits from more than one parent contract e.g.

contract D is A,B,C { ... }

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

1 Like

1. What is the base contract?
In the inheritance pattern, the base contract is the one that inherits variables and functions (at least, as much as it is needed) to other contracts that are derived from it.

2. Which functions are available for derived contracts?
Public and internal functions, defined in the base contract, are available for derived contracts.

3. What is hierarchical inheritance?
Hierarchical inheritance is a pattern where multiple contracts are derived from the same base contract. (it defines contracts that are “siblings”, which is different from the multilevel inheritance, where each contract is defined as a “child” of the previous one)

1 Like
  1. the base contract is the contract that the current contract inherits from
  2. all public or internal functions (not private or external)
  3. hierarchical inheritance happens when more than 1 contract inherits from the same base contract.
1 Like