统计对象创建个数

public class CoutObject {
public static void main(String[] args) {
CoutObject t1=new CoutObject();
CoutObject t2=new CoutObject();
System.out.println("创建对象个数:"+CoutObject.getNum());
}
public static int n;
public CoutObject()
{
n++;
}
public static int getNum()
{
return n;
}
}

 

posted @ 2018-10-21 17:38  故事-已开始。  阅读(247)  评论(0编辑  收藏  举报