I tried to do some example to learn how finalize method work. but I can't get my output in the console that I expected. why finalize method didn't work in the following example after obejct is destroyed ?
package work2;
class Foo {
protected void finalize() {
System.out.println("Object Destroyed."); // not working. why ?
}
}
public class part3 {
public static void main(String[] args) {
Foo bar = new Foo();
bar = null; // destroying the object (Garbage Collection)
System.out.println("finished");
}
}
output of program
finished
Thanks.