Friday, February 27, 2015

What is virtual constructors/destructors?

Question:What is virtual constructors/destructors??

Answer: <B><I>Virtual destructors: </I></B>If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object.&nbsp; &nbsp;There is a simple solution to this problem – declare a virtual base-class destructor. This makes all derived-class destructors virtual even though they don't have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called. &nbsp;<B><I>Virtual constructor: </I></B>Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. &nbsp;Does c++ support multilevel and multiple inheritance? Yes.&nbsp; &nbsp;What are the advantages of inheritance? • It permits code reusability. • Reusability saves time in program development. • It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional. &nbsp;&nbsp;What is the difference between declaration and definition? &nbsp;The declaration tells the compiler that at some later point we plan to present the definition of this declaration.&nbsp; E.g.:&nbsp; void stars () //function declaration &nbsp;The definition contains the actual implementation. E.g.:&nbsp; void stars () // declarator &nbsp;{ &nbsp; for(int j=10; j&gt;=0; j--) //function body &nbsp;&nbsp; cout&lt;&lt;"*"; &nbsp; cout&lt;&lt;endl; &nbsp;}&nbsp;&nbsp;

Tags:Interview Questions, Languages, C++,

Please submit your Interview Answer for the above Question via replying to this post. Thank you for visiting to our blog, Have a Good Day!.



Sponsor Advertisement



Human Resource Management Software

Human Resource Management Software

Powerful, configurable software for human resources management that is easy to manage and remarkably cost-effective, whatever the size of your company. Now there’s a smarter, more efficient way to handle all of your people-related activities. Easy-to-use system manages the full hire-to-retire lifecycle...

No comments:

Post a Comment