查看创建对象的个数

package 作业1;

public class Student{
public static void main(String[] args){
Information a = new Information();
a.OutputInformation();
Information b = new Information();
b.OutputInformation();
}
}

class Information{
static int num=0;
Information(){
num++;
}
public void OutputInformation() {
System.out.println("你已经创建了"+num+"个对象!");
}
}

 

posted @ 2015-10-15 08:30  梦玄庭  阅读(233)  评论(0编辑  收藏  举报