In this program, there are three classes: A, B, and C. B inherits from A, and C inherits from B. This forms a chain of inheritance, with C inheriting from B and B inheriting from A. Each of the classes has a constructor, which is called when an object of that class is created. When an object of class C is created in the main function, the constructor of class A is called first, followed by the constructor of class B, and finally the constructor of class C.
#include<iostream> using namespace std; class A { public: A() { cout<<"Constructor of A class"<<endl; } }; class B: public A { public: B() { cout<<"Constructor of B class"<<endl; } }; class C: 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