0% found this document useful (0 votes)
15 views2 pages

C++ Class Constructors Example

The document contains a C++ program that defines three classes: A, B, and C, where B inherits from A and C inherits from B. When an object of class C is created, it triggers the constructors of A, B, and C in that order, printing messages to the console. The output confirms the sequence of constructor calls as 'Constructor of A class', 'Constructor of B class', and 'Constructor of C class'.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

C++ Class Constructors Example

The document contains a C++ program that defines three classes: A, B, and C, where B inherits from A and C inherits from B. When an object of class C is created, it triggers the constructors of A, B, and C in that order, printing messages to the console. The output confirms the sequence of constructor calls as 'Constructor of A class', 'Constructor of B class', and 'Constructor of C class'.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <iostream>

using namespace std;


class A {
public:
A(){
cout<<"Constructor of A class"
<Kendl;

};
class B: public A {
public:

B(){
cout<<" Constructor of B class"
<<endl;

};
class C: public B{
public:

C(O{
cout<<"Constructor of C class"
<<endl;

};
int main() {
//Creating object of class C
C obj;
return 0;
Output:

Constructor of A class
Constructor of B class
Constructor of C class

You might also like