Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Multilevel inheritance in c++

Multilevel inheritance of enhancement version of single inheritance. multilevel inheritance are using minimum three class coordinations.

Example

AGrandfatherBFatherCChild

In this program given overview of a multilevel inheritance.

Note that class C object are access class B public member functions. And also inherit the property of public member functions of Class A. B is derived from A and inherited publicly. So B is a intermediate base class. And C is child class of B (In this case publicly inherit). So C object also inherit the public member function of class A.

Note : That if B is Private inherit the scenario are change. View example.

Overview of this scenario.

Output

In this case we are not access the Class A member function to class C. Because Class B privately inherit class A. and there are limitation to access this member function accessible to only class B. So How can access Class A member function. This will given in next scenario.

Class B is access public function of class A. And object of class C access the all public member function of class B. the solution is to defined a new memeber function of class B. And use it member function of class A.

Output

Submit your solution in comment section.

Spread the post

Recommended Posts: