forcing a finalize method to run

wxdqz

New Member
In the proceeding code I want to force the finalize method to run for 'a'(a reference of Type 'A' that is pointing to and object of type 'B') whenit is assigned a null. I want to verify that the finalize method for classB will run and that the output will be "class B". As it stands, there isno output when the code is run.What am I doing wrong?class A {int x;protected void finalize () throws Throwable {System.out.println(" classA");}}class B extends A{int x;protected void finalize () throws Throwable {System.out.println(" classB");}public static void main (String [] args) {A a = new B();a = null;System.runFinalization();System.gc();}}
 
Back
Top