日期:2014-05-20 浏览次数:20939 次
class T{
boolean empty=false;
T(boolean status){empty=status;}
void dropout(){empty=true;}
protected void finalize(){
if (empty==false)
System.out.println("error:the tank is still not empty!");
}
}
public class Tank {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
T tank1=new T(false);
T tank2=new T(false);
tank1.dropout();
System.runFinalization();
System.gc();
}
}
class T{
boolean empty=false;
T(boolean status){empty=status;}
void dropout(){empty=true;}
protected void finalize() throws Throwable{
[color=#FF0000]System.out.println("the end");[/color]
if (empty==false)
System.out.println("error:the tank is still not empty!");
}
}
public class Tank {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
T tank1=new T(false);
//new T(false); //把这个注释去掉的话,就使内存中产生了一个可能被回收的对象
tank1.dropout(); //不写这句话就能打印出error...
tank1=null;
//System.runFinalization();
System.gc();
}
}