C++ | Inheritance | Question 2
Output?
#include <iostream> using namespace std; class Base1 { public: ~Base1() { cout << " Base1's destructor" << endl; } }; class Base2 { public: ~Base2() { cout << " Base2's destructor" << endl; } }; class Derived: public Base1, public Base2 { public: ~Derived() { cout << " Derived's destructor" << endl; } }; int main() { Derived d; return 0; } |
chevron_right
filter_none
(A)
Base1's destructor Base2's destructor Derived's destructor
(B)
Derived's destructor Base2's destructor Base1's destructor
(C)
Derived's destructor
(D) Compiler Dependent
Answer: (B)
Explanation: Destructors are always called in reverse order of constructors.
Quiz of this Question
Recommended Posts:
- C++ | Inheritance | Question 12
- C++ | Inheritance | Question 3
- C++ | Inheritance | Question 4
- C++ | Inheritance | Question 5
- C++ | Inheritance | Question 14
- C++ | Inheritance | Question 1
- C++ | Inheritance | Question 9
- C++ | Inheritance | Question 8
- C++ | Inheritance | Question 13
- C++ | Inheritance | Question 10
- C++ | Inheritance | Question 11
- C++ | Inheritance | Question 6
- C++ | Inheritance | Question 7
- Java | Inheritance | Question 9
- Java | Inheritance | Question 7



