#include<iostream>
using namespace std;
class Base {
public :
Base() { cout<< "Constructor: Base" <<endl; }
virtual ~Base() { cout<< "Destructor : Base" <<endl; }
};
class Derived: public Base {
public :
Derived() { cout<< "Constructor: Derived" <<endl; }
~Derived() { cout<< "Destructor : Derived" <<endl; }
};
int main() {
Base *Var = new Derived();
delete Var;
return 0;
}
|
(A)
Constructor: Base
Constructor: Derived
Destructor : Derived
Destructor : Base
(B)
Constructor: Base
Constructor: Derived
Destructor : Base
(C)
Constructor: Base
Constructor: Derived
Destructor : Derived
(D)
Constructor: Derived
Destructor : Derived
Answer: (A)
Explanation: Since the destructor is virtual, the derived class destructor is called which in turn calls base class destructor.
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!
Last Updated :
19 Oct, 2021
Like Article
Save Article