1.

What is the output of the below code?

Answer»

#include<iostream> using namespace std; class BaseClass1 { public: BaseClass1() { cout << " BaseClass1 constructor called" << endl; } }; class BaseClass2 { public: BaseClass2() { cout << "BaseClass2 constructor called" << endl; } }; class DERIVEDCLASS: public BaseClass1, public BaseClass2 { public: DerivedClass() { cout << "DerivedClass constructor called" << endl; } }; int main() { DerivedClass derived_class; return 0; }

Output:

BaseClass1 constructor calledBaseClass2 constructor calledDerivedClass constructor called

Reason:
The above program demonstrates Multiple INHERITANCES. So when the Derived class’s constructor is called, it automatically calls the Base class's CONSTRUCTORS from left to right ORDER of INHERITANCE.



Discussion

No Comment Found