Skip to content
Sharp

Engineering Interviews · interview question

In Java, what is the role of the finalize() method?

Multiple choiceMediumchapter-20-curatedpremiumengineering-interviewsjvm-trivia
Choose one answer
Answer and explanation

Correct answer

D. It is called by the garbage collector before an object is removed.

Why

The finalize() method is called by the garbage collector before an object is removed from memory. It provides an opportunity to clean up non-memory resources, but its use is generally discouraged due to unpredictability.

Test yourself on Engineering Interviews

A free test with instant, explained results. No account needed.

Start free test
All Engineering Interviews questions →