Machine-translated by Google. Questions are authored in English.
Top

Polymorphism and Virtual Functions Questions and Answers

Answer: C

If the base class destructor is not virtual, the destructor in the derived class cannot be called when the object is accessed through a pointer to the base class.

When delete is applied to a base class pointer that points to a derived object, the destructor is chosen by the pointer's static type unless it is virtual. Only the base class destructor runs, so the derived part is not cleaned up, which can leak resources (strictly, the behaviour is undefined).

A non-virtual base destructor can still be called and still has a body. It is the derived class destructor, not the base one, that is skipped, so options A, B and D are wrong.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Polymorphism and Virtual Functions Questions and Answers || Polymorphism and Virtual Functions MCQ Questions and Answers || Polymorphism and Virtual Functions GK Questions and Answers || Polymorphism and Virtual Functions GK MCQ Questions || Polymorphism and Virtual Functions Multiple Choice Questions and Answers || Polymorphism and Virtual Functions GK || GK on Polymorphism and Virtual Functions || Object Oriented Programming Questions and Answers || Object Oriented Programming MCQ Questions and Answers || Object Oriented Programming GK Questions and Answers || GK on Object Oriented Programming