03-课后作业-查询创建了多少对象

//查询创建了多少对象

public class Test{

public static void main( String args[]){

Test a= new Test();

a.OutputInformation();

Test b= new Test();

b.OutputInformation();

Test c= new Test();

c.OutputInformation();

Test d= new Test();

d.OutputInformation();

}

 

static int num=0;

public Test(){

num++;

}

public void OutputInformation(){

System.out.println("已经创建了"+num+"个对象!");

}

}

截图

 

posted on 2017-10-19 19:20  王行行  阅读(136)  评论(0编辑  收藏  举报

导航