代码:
public class Test
{
static int number;
public Test()
{
number++;
}
public static int getNumb(int number)
{
return number; //返回得到numb的最终的值
}
public static void main(String args[])
{
Test t1=new Test();
Test t2=new Test();
System.out.println("目前创建了"+Test.getNumb(number)+"个对象");
}
}
运行结果: