+ 3
C#Love Chat-8.Final
well, Mandy finally fell in love with us, and she is trying to tell us about it. Let's help her)) In this code I tested constructors and destructors. I gonna code with Java next (actually, I have already had a bad trying),thus could you please tell me how to use destructor with Java? https://code.sololearn.com/cDgkCuk0u2sw/?ref=app
1 Answer
+ 6
Java doesn't have a true destructor, but uses the finalize() method which is "called by the garbage collector on an object when garbage collection determines that there are no more references to the object". So, it is the closest thing to a destructor, but there is no actual way to tell exactly when it will be called. Especially in larger programs. In small programs that only use a few objects that are to be destroyed just before the program closes you may not see much, if any, difference. Just keep in mind that results may vary in the future.