Called by GC before reclaiming an object's memory.
The finalize() method is a mechanism for cleanup before an object is garbage collected, but it's unpredictable and generally discouraged. Relying on it can lead to resource leaks. It's better to use try-with-resources or explicit cleanup methods. For instance, in handling file resources, always close files explicitly.