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+"个对象!");

}

}

截图

原文地址:https://www.cnblogs.com/0710whh/p/7694277.html