Παράδειγμα:
import gr.aueb.dds.BIO;
class Point {
private int x, y;
// Point constructor
Point(int ix, int iy) {
x = ix;
y = iy;
}
// Point destructor
public void finalize() {
BIO.println("Another point bites the dust");
BIO.print("The point was at ");
display();
}
public void display() {
BIO.print("(x=" + x);
BIO.println(", y=" + y + ")");
}
static public void main(String args[]) {
Point a = new Point(1, 2);
Point b = new Point(5, 8);
a = b;
// Force the garbage collector to run
System.gc();
}
}