Answer Posted / rock
When a derived class object pointed to by a base class
pointer dynamically is deleted only the base class
destructor is invoked inorder to even invoke derived class
destructor we use virtual destructor.
class shape
{
virtual ~shape(){}
};
class circle:public shape
{
~circle(){}
};
void main()
{
shape *sh = new circle;
delete sh; //both the destructors are invoked
}
If virtual keyword is not added to the base class
destructor only the base class destructor is called.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How do you define a class in oop?
What is inheritance in oop?
What is constructor in oop?
What is data binding in oops?
What are the 4 main oop principles?
What is use of overloading?
What is the problem with multiple inheritance?
Can destructor be overloaded?
What is the purpose of polymorphism?
What does I oop mean?
Which language is pure oop?
What is the difference between a mixin and inheritance?
Which is better struts or spring?
What is encapsulation in oop?
What is a null tree?