C++ Programming - Objects and Classes - Discussion

Discussion :: Objects and Classes - General Questions (Q.No.3)

3. 

Which of the following statement is correct regarding destructor of base class?

[A]. Destructor of base class should always be static.
[B]. Destructor of base class should always be virtual.
[C]. Destructor of base class should not be virtual.
[D]. Destructor of base class should always be private.

Answer: Option B

Explanation:

No answer description available for this question.

Ashish said: (Jul 8, 2012)  
Because the initialization of base class objects must not be destroyed by deleting object of derived class. That is base class destructor must not be called upon calling derived class destructor.

Naseem Asraf said: (Aug 17, 2012)  
Because the initialization of base class objects must not be destroyed by deleting object of derived class. That is base class destructor must not be called upon calling derived class destructor.

Abhishek Singh said: (Aug 29, 2012)  
If object of derived class is created, then constructor of derived class is called automatically, and if base class constructor has same name, then it is called also.

Same scenario will be happened if Destructor of base class is not virtual.

Abhishek Singh said: (Aug 29, 2012)  
If object of derived class is created, then constructor of derived class is called automatically, and if base class constructor has same name, then it is called also.

Same scenario will be happened if Destructor of base class is not virtual.
so it should always be virtual.

Nagnath said: (Sep 18, 2012)  
Because the initialization of base class objects must not be destroyed by deleting object of derived class. That is base class destructor must not be called upon calling derived class destructor.

Neha said: (Feb 18, 2013)  
Because, the initialization of base class object must not be destroyed by deleting object of derived class. That is base class.

Destructor must not be called upon calling derived class destructor.

Ajay said: (Oct 7, 2014)  
why we use concept of virtual?

Shalin said: (Feb 28, 2015)  
Why constructor can not be created virtual?

Guriya said: (Apr 25, 2015)  
Because constructor is not contained Virtual method table in memory.

Keerthana said: (May 8, 2015)  
What happens if destructor is not virtual?

Shaan said: (Jul 6, 2015)  
Because if we assign derived class in to base class pointer then if we call delete then only base class destructor will call, base class destructor will not call.

So object will not fully destroy. And now if the destructor of base class is virtual then derived class destructor will call and object will fully destroy.

Divya Agrawal said: (Mar 1, 2016)  
But how destructor uses virtual? It is not getting.

Gaurav said: (Mar 4, 2016)  
There is no need to use destructor as virtual because the principle of destructor is to delete the constructor and free the memory allocated by constructor and virtual function should transfer the function call from base class to derive i.e. if want to delete the constructor of both the classes but the can't happen it should be delete only derived class object.

Sumit Sharma said: (Feb 17, 2017)  
Significance of virtual function is to provide late binding by restricting the early binding. So destructor should be always virtual so respective descended class's destruction execute instead of parent class destructior, when accesed through pointer as a refrence of the oblect.

Chandu Reddy said: (Dec 19, 2019)  
What is the difference between pure virtual and absult virtual class?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.