🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Inheritance and Virtual Functions: all 10 questions

Quiz: Inheritance and Virtual Functions · Question 4 of 10

Why should a polymorphic base class have a virtual destructor?

Why should a polymorphic base class have a virtual destructor?

  1. A.To make it faster
  2. B.So deleting through a base pointer also runs the derived destructor
  3. C.Destructors can't be virtual
  4. D.To allow copying
Answer & explanation

Correct answer: So deleting through a base pointer also runs the derived destructor

Otherwise the derived part isn't cleaned up properly.

Can you get the rest right without peeking?

Take the timed Quiz: Inheritance and Virtual Functions quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →