Discussion :: Constructors and Destructors - General Questions (Q.No.3)
Can a class have virtual destructor?
Answer: Option A
No answer description available for this question.
|Padma said: (Jul 17, 2012)|
|How the destructor can be a virtual ?|
|Swami Vivekanand L. said: (Sep 19, 2012)|
|Destructor can be virtual because whenever the object goes in out of the scope then we have to delete it explicitly i.e. we need to call the destructor explicitly so destructor should made as virtual destructor like same as virtual function.|
|Surya.T said: (Aug 12, 2013)|
|What is mean by virtual function?|
|Nishant Singh said: (Aug 15, 2013)|
|Virtual functions provide run time polymorphism as the function to be executed is decided at run-time.|
|Dwarika said: (Sep 15, 2013)|
|Destructor can be virtual because whenever the object goes in out of the scope then we have to delete it explicitly.|
|Priyanka said: (Dec 29, 2013)|
|But if object goes out of scope, destructor is called automatically. Then why we need to call it explicitly?|
|Kjs said: (Dec 31, 2013)|
|In C++ there is no automatic garbage collection.|
|Velmurugan said: (Mar 12, 2014)|
|Destructor is invisibility in your program and it's call automatically. Because every constructor program using inside destructor.|
|Lilly said: (Mar 13, 2014)|
|Please clarify my doubt. Class is declared as virtual then how the class contain destructor?|
|Sai said: (Jul 5, 2014)|
|Can constructors be virtual?|
|Krunal said: (Aug 13, 2014)|
Because compiler does not provide any default constructor when we provided explicitly.
|Abc said: (Dec 26, 2014)|
|What is the meaning of explicitly call?|
|Annonymous said: (Mar 7, 2015)|
Explicitly means we have to delete manually.
|Waseem Ahmad Naeem said: (Jun 5, 2015)|
|If an object goes out of scope destructor is called automatically then why we need to call it explicitly?|
|Arun said: (Apr 1, 2016)|
|What happens when a virtual function is declared as static?|
|Amit said: (Jul 6, 2016)|
|Virtual destructors are used to delete memory allocated for derived class. By default the destructor deletes memory just for base class.|
|Shikha Singh said: (Mar 23, 2017)|
No, because it doesn't make any sense in C++.
Virtual functions are invoked when you have a pointer/reference to an instance of a class.
Static functions aren't tied to a particular instance, they're tied to a class.
C++ doesn't have pointers-to-class, so there is no scenario in which you could invoke a static function virtually.
|Gopika said: (Oct 14, 2017)|
|What is meant by the term warping functions associated with virtual destructors?|
|Amir Sandila said: (Oct 24, 2017)|
|What is meant by virtual?|
|Ankit said: (May 21, 2018)|
|Why is virtual constructor not possible? Please explain.|
|Siva Darling said: (Aug 9, 2019)|
|What is virtual destructor? please explain.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.