?? finalize.java
字號:
class point
{
int x,y;
point(int a,int b)
{
this.x=a;
this.y=b;
System.out.println("父類先構建 !");
}
public void finalize()
{
System.out.println("父類回收!");
}
String getstring()
{
return "x="+x+"; y="+y;
}
}
class circle extends point
{
int radius;
circle(int a,int b,int r)
{
super(a,b);
radius=r;
System.out.println("類 "+getClass().getName()+" 構建:" +getstring() );
}
public void finalize()
{
this.x=0;
this.y=0;
this.radius=0;
System.out.println("類 "+getClass().getName()+" 回收:"+getstring() );
}
String getstring()
{
return super.getstring()+"; radius="+radius;
}
}
public class finalize
{
public static void main(String args[])
{
point c1,c2;
c1=new circle(11,22,33);
c2=new circle(77,88,99);
c1=null;
c2=null;
System.gc();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -