A

Admin • 833.24K Points
Coach

Q. Which class constructor is called in the following C++ code?

Code:
#include<iostream>

using namespace std;

class A {
public:
A()
{ cout << " The constructor of class A is called." << endl; }
};

class B {
public:
B()
{ cout << " The constructor of class B is called." << endl; }
};

class C: public A, public B {
public:
C()
{ cout << " The constructor of class C is called." << endl; }
};

int main()
{
C c;
return 0;
}
  • (A) Classe C
  • (B) Class A and B
  • (C) Class A, B and C
  • (D) Compilation error
  • Correct Answer - Option(C)
  • Views: 30
  • Filed under category C++
  • Hashtags:

Explanation by: Admin

In case of multiple inheritance, the constructors of parent classes are always called in the order of inheritance from left to right and the destructors are called in reverse order.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.