#include<iostream>
using namespace std;
class Base1 {
public :
Base1()
{ cout << " Base1's constructor called" << endl; }
};
class Base2 {
public :
Base2()
{ cout << "Base2's constructor called" << endl; }
};
class Derived: public Base1, public Base2 {
public :
Derived()
{ cout << "Derived's constructor called" << endl; }
};
int main()
{
Derived d;
return 0;
}
|
(A) Compiler Dependent
(B) Base1′s constructor called
Base2′s constructor called
Derived’s constructor called
(C) Base2′s constructor called
Base1′s constructor called
Derived’s constructor called
(D) Compiler Error
Answer: (B)
Explanation: When a class inherits from multiple classes, constructors of base classes are called in the same order as they are specified in inheritance.
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!