So i was studying Garbage collection, how it works internally inside the java virtual machine.
I came across a method called finalize(which is situated in java.lang.Object
).
I tried this code:
class Demo {
int x= 10;
int y = 20;
public void finalize() throws Throwable {
System.out.println("Finalize method");
}
static void show() {
Demo d1= new Demo();
display();
}
static void display()
{
Demo d2 = new Demo();
}
}
class Temp {
public static void main(String args[]) throws Exception {
Demo.show();
}
}
I was able to compile this code, but when I run this code there is no exception and no output.
Please assist me if you can.
I tried Google and many other reputed blogs to sort out my Problem (tutorialsPoint), (JavaRevisited).
I even searched stackoverflow, but i am unable to solve my problem.
P.S :- Output should be Finalize method which you can point out. PLEASE assist me.
To summarize, my question is: Why cant I execute the Finalize Method?