标签:
截图
//通过静态字段和构造函数知道所创建对象个数
//刘启明,October 17,2015
package Demo;
class ObjectNumbers{
static int number=0;
public ObjectNumbers() {
System.out.println("已经创建了"+(++number)+"个对象!!");
}
}
public class Search {
public static void main(String[] args) {
ObjectNumbers obj1=new ObjectNumbers();
ObjectNumbers obj2=new ObjectNumbers();
ObjectNumbers obj3=new ObjectNumbers();
ObjectNumbers obj4=new ObjectNumbers();
}
}
标签:
原文地址:http://www.cnblogs.com/2014lqm-cn/p/4887677.html