Disable ads (and more) with a membership for a one time $4.99 payment
Which method does Java automatically call on an object before garbage collection?
clean()
finalize()
delete()
remove()
The correct answer is: finalize()
Java has a feature called garbage collection which automatically frees up any memory that is no longer being used by an object. Before destroying an object, Java automatically calls its finalize() method to perform any cleanup tasks, such as closing open files or releasing resources. Therefore, the incorrect options are A clean(), C: delete(), and D: remove() as they are not methods specifically used for garbage collection in Java.