How Does Virtual Destructor Work In Java?


3 Answers

Florio Potter Profile
Florio Potter answered

Virtual Destructor. Deleting a derived class object using a pointer to a base class that has a non-virtual destructor results in undefined behavior. To correct this situation, the base class should be defined with a virtual destructor. For example, following program results in undefined behavior. If you want to know in detail then you can get help at CodeAvail- Online Computer Science Assignment

rahul Profile
rahul answered
We don't write destructors in JAVA as we do in C++. The removal of unused objects is taken care of by garbage collector in JAVA.
Anonymous Profile
Anonymous answered
The reason destructors (the finalize method) aren't generally written in java is because finalize is very unreliable - it may never be called at all. Java doesn't have deterministic destructors.

Answer Question