Easy Tutorial
❮ Arrays Union Java9 Multirelease Jar ❯

Java Object finalize() Method

Java Object Class


The Object finalize() method is used to trigger operations when an instance is about to be reclaimed by the garbage collector.

Syntax

protected void finalize()

Parameters

Return Value

No return value.

Example

The following example demonstrates the use of the finalize() method:

Example

import java.util.*;

class tutorialproTest extends GregorianCalendar {
    public static void main(String[] args) {
        try {
            // Create tutorialproTest object
            tutorialproTest cal = new tutorialproTest();

            // Print current time
            System.out.println("" + cal.getTime());

            // Finalize cal
            System.out.println("Finalizing...");
            cal.finalize();
            System.out.println("Finalized.");

        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
}

The above program execution results are:

Sun Oct 11 11:36:46 CST 2020
Finalizing...
Finalized.

Java Object Class

❮ Arrays Union Java9 Multirelease Jar ❯