-
forcing a finalize method to run
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') when
it is assigned a null. I want to verify that the finalize method for class
B will run and that the output will be "class B". As it stands, there is
no output when the code is run.
What am I doing wrong?
class A {
int x;
protected void finalize () throws Throwable {System.out.println(" class
A");}
}
class B extends A{
int x;
protected void finalize () throws Throwable {System.out.println(" class
B");}
public static void main (String [] args) {
A a = new B();
a = null;
System.runFinalization();
System.gc();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|