Skip to content
Sharp

Engineering Interviews · interview question

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

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

Correct answer

C. It is called by the garbage collector before an object is collected.

Why

The finalize() method is called by the garbage collector before an object is collected to allow it to clean up resources. However, it is generally discouraged due to unpredictability in timing and execution, and alternative resource management techniques are preferred.

Test yourself on Engineering Interviews

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

Start free test
All Engineering Interviews questions →