ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  OOPS
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
what is virtual destructor
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is virtual destructor
Answer
# 1
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 ?    1 Yes 0 No
Suresh.k (portblair)
 
  Re: what is virtual destructor
Answer
# 2
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 ?    3 Yes 0 No
Kamil Mohamed
 
 
 
  Re: what is virtual destructor
Answer
# 3
virtual destructor is just to remove the variable without 
knowing its type.....
 
Is This Answer Correct ?    0 Yes 1 No
Rahul
 
  Re: what is virtual destructor
Answer
# 4
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 ?    1 Yes 0 No
Isha
 
  Re: what is virtual destructor
Answer
# 5
Normally virtual destructor is used to destroy a base class 
object without knowing it's type...
 
Is This Answer Correct ?    0 Yes 1 No
Maria Alex
 

 
 
 
Other OOPS Interview Questions
 
  Question Asked @ Answers
 
//what is wrong with the programme?? #include<iostream.h> template <class first> class dd { first i; public: void set(); void print(); }; void dd< first>:: set() { cin>>i; } void dd< first>::print() { cout<<"\n"<<i; } void main() { dd <char>g; g.set(); g.print(); }  1
what is virtual function? Infosys11
What is late bound function call and early bound function call? Differentiate.  2
What is a mixin class?  3
In what situation factory design patterns,DAO design patterns,singleton design patterns should be applied.?  1
What are generic functions and generic classes?  2
In multilevel inheritance constructors will be executed from the .... class to ... class  1
What is the Advantage of Interface over the Inheritance in OOPS?  2
What is abstraction?  6
What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; } 1) The computer will output "0123...99" 2) The computer will output "0123...100" 3) The output is undefined  3
What is a linked list? IBM4
Difference between realloc() and free? HP3
what is the basic concept of inheritance?  4
Why u change company? BOB-Technologies3
Please tell me the oops concept with detailed answer EEE4
What is a template?  5
Name an advantage of linked list over array? IBM6
sir i want to know which posting to apply since i am BE CSE.. also want to know what are the rounds there for my interview...Expecting for ur valuable answer....  1
What is virtual constructors/destructors?  3
tell about copy constructor Siemens1
 
For more OOPS Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com