跟踪某个类中创建对象的个数 class New{ static int n ; New(){ n+=1; //每定义一个对象,n+1 } static void Count(){ System.out.println(n); //输出静态变量 } }