Question:Consider the sample code given below and answer the question that follows.
class Person
{
public:
   Person();
      virtual ~Person();
};
class Student : public Person
{
public:
   Student();
   ~Student();
};

main()
{
   Person *p = new Student();
   delete p;
}
Why is the keyword "virtual" added before the Person destructor? 

A To make it impossible for this particular destructor to be overloaded 

B To ensure that correct destructor is called when p is deleted 

C To ensure that the destructors are called in proper order 

D To improve the speed of class Person's destruction 

E To prevent the Person class from being instantiated directly making it an abstract base class 

+ Answer
+ Report
Total Preview: 928

Copyright © 2024. Powered by Intellect Software Ltd