Java examples for Object Oriented Design:finalize
A Finalize Class That Overrides the finalize() Method of the Object Class
public class Main { public static void main(String[] args) { // Create many objects, say 20000 objects. for(int i = 0; i < 20000; i++) { new Finalize(i); } /* ww w .j a va2 s. co m*/ } } class Finalize { private int x; public Finalize(int x) { this.x = x; } public void finalize() { System.out.println("Finalizing " + this.x); /* Perform any cleanup work here... */ } }