Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


what is virtual destructor

Answers were Sorted based on User's Feedback



what is virtual destructor..

Answer / isha

Dear friend , you have done a mistake..
Example:

class Employee {
virtual ~Employee() {}
};

class Manager : public Employee {
~Manager() {}
}

Employee * m = new Manager();//here was the mistake
delete m; // <--

Is This Answer Correct ?    9 Yes 0 No

what is virtual destructor..

Answer / kamil mohamed

virtual destructor is recommended when you want to destroy
(delete) an object through it's parent pointer. This good
habit enforces proper cleanup of derived classes

Example:

class Employee {
virtual ~Employee() {}
};

class Manager : public Employee {
~Manager() {}
}

Manager * m = new Employee();
delete m; // <--

Is This Answer Correct ?    6 Yes 1 No

what is virtual destructor..

Answer / 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

what is virtual destructor..

Answer / pankajkolte

Virtual Destructor is used basically to ensure proper the
sequence of call to destructor.

class Employee {
virtual ~Employee() {}
};

class Manager : public Employee {
~Manager() {}
}

Employee * m = new Manager();//here was the mistake
delete m; // <-

In this case base class destructor if marked as virtual so
as derived class destructor will get called first then base
class destructor.

Is This Answer Correct ?    2 Yes 0 No

what is virtual destructor..

Answer / suresh.k (portblair)

Using virtual destructors, you can destroy objects without
knowing their type - the correct destructor for the object
is invoked using the virtual function mechanism. Note that
destructors can also be declared as pure virtual functions
for abstract classes.

if someone will derive from your class, and if someone will
say "new Derived", where "Derived" is derived from your
class, and if someone will say delete p, where the actual
object's type is "Derived" but the pointer p's type is your
class.

Is This Answer Correct ?    2 Yes 4 No

what is virtual destructor..

Answer / rahul

virtual destructor is just to remove the variable without
knowing its type.....

Is This Answer Correct ?    0 Yes 3 No

what is virtual destructor..

Answer / maria alex

Normally virtual destructor is used to destroy a base class
object without knowing it's type...

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More OOPS Interview Questions

what is the use of mutable key word

3 Answers   HCL,


What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.

2 Answers  


why c++ is called OOPS? waht is inherutance? what is compiler?

5 Answers  


WAP to generate 2n+1 lines of the following pattern on the computer screen:

2 Answers  


What are the benefits of interface?

0 Answers  


how to create thread in java?

17 Answers   IBM, Infosys, Wipro,


Why and when is a virtual destructor needed?

5 Answers  


what's the basic's in dot net

0 Answers   informatics,


What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?

0 Answers   IBM,


what is a class

6 Answers  


What is a class?

32 Answers   Infosys, TCS, Thylak,


In multilevel inheritance constructors will be executed from the .... class to ... class

2 Answers   ABCO, TCS,


Categories