D

Dharmendra Sir • 3.53K Points
Extraordinary

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: 124
  • Filed under category C++

Explanation by: Dharmendra Sir
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.


Question analytics