πŸ“Š C++
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
πŸ’¬ Discuss
βœ… Correct Answer: (C) Class A, B and C

Explanation: 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.

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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
198
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Dharmendra Sir
Publisher
πŸ“ˆ
84%
Success Rate