VOOZH about

URL: https://www.geeksforgeeks.org/cpp/constructor-in-multilevel-inheritance-in-cpp/

⇱ Constructor in Multilevel Inheritance in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Constructor in Multilevel Inheritance in C++

Last Updated : 7 Mar, 2022

Constructor is a class member function with the same name as the class. The main job of the constructor is to allocate memory for class objects. Constructor is automatically called when the object is created. 

Multilevel Inheritance

Derivation of a class from another derived class is called Multilevel Inheritance. Class A is the base class for the derived class B, which in turn serves as a base class for the derived class C. Class B provides a link for the inheritance between A and C and is known as an intermediate base class. The chain A, B, C is known as the inheritance path.

👁 Multilevel Inheritance

Example 1: Below is the C++ program to show the concept of constructor in multilevel Inheritance.


Output
Base class A constructor 
Class B constructor 
Class C constructor 

Example 2: Below is the C++ program to implement multilevel inheritance.


Output
Sum is:11
Difference is:15
Product is:200
Comment