System.runFinalization() in Java

System.runFinalization(): This method is available in java.lang.System class of Java.

Syntax:

void java.lang.System.runFinalization()

This method runs the finalization methods of any objects pending finalization. Calling this method suggests that the Java Virtual Machine expend effort toward running the finalize methods of objects that have been found to be discarded but whose finalize methods have not yet been run. When control returns from the method call, the Java Virtual Machine has made the best effort to complete All outstanding finalizations.

Parameters: NA

Exceptions: NA

Approach

Java

public class SystemrunFinalization {
    public static void main(String[] args) {

        System.out.println("Runs finalization of any pending objects");
        System.runFinalization();

        System.out.println("Runs successfully");
    }
}


Output:

Runs finalization of any pending objects Runs successfully


No comments:

Post a Comment