踪某个类所创建对象的个数

public class new1 {
static int n=0;
new1(){
	n++;
}
static void count(){
	System.out.println(n);
}

}
public class lab {
public static void main(){
	new1 a=new new1();
	System.out.println(a);
	new1 b=new new1();
	System.out.println(b);
	new1 c=new new1();
	System.out.println(c);
	new1.count();
}
}

  

posted @ 2018-10-21 16:15  竹林清竹  阅读(90)  评论(0编辑  收藏  举报