class A
{
private int i = 1;
private static int cnt = 0;
public A()
{
cnt++;
}
public A(int i)
{
this.i = i;
cnt++;
}
public static int getCnt()
{
return cnt;
}
}
class D
{
public static void main(String[] args)
{
System.out.printf("构造的对象个数为%dn",A.getCnt());
A aa1 = new A();
System.out.printf("构造的对象个数为%dn",A.getCnt());
A aa2 = new A();
System.out.printf("构造的对象个数为%dn",A.getCnt());
}
}
最后
以上就是深情太阳最近收集整理的关于写程序统计对象的个数的全部内容,更多相关写程序统计对象内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复