1.下面的代码,为什么结果是4,4,748 ?
2.finalize() 是属于覆盖的方法吗?
class TestGC{
public static void main(String[] args) {
while (GC.flag){new GC();}
System.out.println(GC.i);
System.runFinalization(); System.out.println(GC.i);
System.gc(); System.out.println(GC.i);
}
}
class GC{
static int i; static boolean flag=true;
public void finalize() {
i++;
flag=false;
}
};
2.finalize() 是属于覆盖的方法吗?
class TestGC{
public static void main(String[] args) {
while (GC.flag){new GC();}
System.out.println(GC.i);
System.runFinalization(); System.out.println(GC.i);
System.gc(); System.out.println(GC.i);
}
}
class GC{
static int i; static boolean flag=true;
public void finalize() {
i++;
flag=false;
}
};