What is virtual constructors/destructors?

Answer Posted / nk

There is nothing like virtual constructors but we can have
virtual destructors so that the destructor of the correct
object is called.
Ex.

Base *bptr = new derived()

delete bptr; then the destructor of the derived objetc is
called when the base destructor is marked as virtual.

else destructore of base class is called and may lead to
memory leak if we have allocated any new memory.

Is This Answer Correct ?    18 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

4243


What is overriding vs overloading?

585


Can you name some types of inheritance?

641


What is the difference between abstraction and polymorphism?

618


can inline function declare in private part of class?

3658






what are the different types of qualifier in java?

1843


What is solid in oops?

613


What is data binding in oops?

588


What is an interface in oop?

595


how to get the oracle certification? send me the answer

1670


What is constructor in oop?

589


What is the main feature of oop?

621


IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?

1582


What is abstraction and encapsulation?

575


Get me a number puzzle game-program

1694