📄 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 + -