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
Are polymorphisms mutations?
What is the significance of classes in oop?
What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?
what are the ways in which a constructors can be called?
How is polymorphism achieved?
Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.
how to get the oracle certification? send me the answer
What are the three parts of a simple empty class?
Why do we use oops?
explain sub-type and sub class? atleast u have differ it into 4 points?
what type of question are asked in thoughtworks pair programming round ?
What is the point of polymorphism?
How to improve object oriented design skills?
Can you explain polymorphism?
What exactly is polymorphism?