This program demonstrates how to create multiple base classes using multiple inheritance in C++. Here, we have three classes: A, B, and C. A and B are base classes and C is a derived class that inherits from both A and B. In the main() function, an object of C class is created using the default constructor. When the object is created, first the A class constructor is called followed by the B class constructor and then the C class constructor.
#include<iostream> using namespace std; class A { public: A() { cout<<"Constructor of A class"<<endl; } }; class B { public: B() { cout<<"Constructor of B class"<<endl; } }; class C: public A, public B { public: C() { cout<<"Constructor of C class"<<endl; } }; int main() { C obj; return 0; }To download raw file Click Here
Constructor of A class Constructor of B class Constructor of C class
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions