Vidyalelo
C++ Programming · Q44

Object Oriented Programming in C++

Programming · C++ Programming · question 44

Q44

What will be the output of the following C++ code? #include using namespace std; class Base public: Base() cout<<"Constructing Base "; virtual~Base() cout<<"Destructing Base "; ; class Derived: public Base public: Derived() cout<<"Constructing Derived "; ~Derived() cout<<"Destructing Derived "; ; int main(void) Derived *d = new Derived(); Base *b = d; delete b; return 0;

A.
Constructing Base
Constructing Derived
Destructing Base
B.
Constructing Base
Constructing Derived
Destructing Derived
Destructing Base
Answer
C.
Constructing Base
Constructing Derived
Destructing Base
Destructing Derived
D.
Constructing Derived
Constructing Base
Destructing Base
Destructing Derived

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board