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                      
tip   To Refer this Site to Your Friends   Click Here
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
In c++ there is only virtual destructors, no constructors. Why?
 Question Submitted By :: Tribhuvan Sharma
I also faced this Question!!     Rank Answer Posted By  
 
  Re: In c++ there is only virtual destructors, no constructors. Why?
Answer
# 1
constructors are invoked at the time of object creation.
The v-table for virtual function mechanism is not 
intialised properly during the constructor invocation.
So constructors cannot be virtual

But,destructors can be virtual.Because the V-table is 
properly initialised at the time of object creation.
So the v-table is available for the destructors.
Destructors can be made pure virtual also.But unlike other 
member functions,it must be redfined outside the class.
 
Is This Answer Correct ?    2 Yes 1 No
Uma Sankar Pradhan
 
  Re: In c++ there is only virtual destructors, no constructors. Why?
Answer
# 2
Since OOPS basics says always base class object to be 
created and than its derivatives. So just consider the case 
where we try to create object of derived class with virtual 
contructor since pointer points to derived type object it 
fetches derived constructor directly, without its base 
class object constructed( instantiated )...
So Constructor cannot be made virtual bt when comes to case 
of Destructor object destuction process must be reverse...
So we must make destructor as virtual.
This applies only when we going for Dynamic Memory 
Allocation...

If, on the other hand, you were to have a pointer to object 
A and assign it a dynamic object B, when you destroy it, 
only object A's destructor is called and object B part of 
the object is never destroyed. Virtual destructors are used 
to solve this problem and destroy the objects in the right 
order.
 
Is This Answer Correct ?    3 Yes 0 No
Bala Preethi
 
 
 

 
 
 
Other OOPS Interview Questions
 
  Question Asked @ Answers
 
Definition of Object Oriented Programming in single line? TCS14
What is namespace?  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 an object? HCL7
WHEN A COPY CONSTER IS CALL ?  1
what is the function of 'this' operator ?  4
polymorphism means? BFL2
What is Object and Class? What are the differences between them?  3
what is difference b/w object based and object oriented programming language? Infosys2
What are virtual functions?  2
What is command routing in MFC GE1
When is it necessary to use member-wise initialization list in C++?  1
Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference between interfaces and abstract class?  3
What is the output of the following code: int v() { int m=0; return m++; } int main() { cout<<v(); } 1) 1 2) 0 3) Code cannot compile  3
what is meant by files? Infosys2
what is the difference between <stdio.h>and "stdio.h"?  2
What is public, protected, private? Satyam4
In multilevel inheritance constructors will be executed from the .... class to ... class  1
What is the difference between an object and a class?  2
what is the basic concept of inheritance?  3
 
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