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
What is the difference between inheritance and polymorphism?
What is abstraction in oops with example?
can inline function declare in private part of class?
What does it mean when someone says I oop?
what are the ways in which a constructors can be called?
i got a backdoor offer in process global,Bangalore..Can i work with it?
What language is oop?
Why interface is used?
What is the importance of oop?
What is a class in oop?
What is an advantage of polymorphism?
What is class encapsulation?
Why do we use inheritance?
Can we have inheritance without polymorphism?
What is a class and object?