A Finalize Class That Overrides the finalize() Method of the Object Class - Java Object Oriented Design

Java examples for Object Oriented Design:finalize

Description

A Finalize Class That Overrides the finalize() Method of the Object Class

Demo Code

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... */
  }
}

Result


Related Tutorials