查看类创建了几个对象

package lianxi6;

class Foo
{
 static int n=0;
 Foo()
 {
  n++;
 }
 
 int a,b,c;
 public void shuchu()
 {
 
 };
 
}
public class 课堂练习 {

 public static void main(String[] args) {
  // TODO 自动生成的方法存根

  Foo obj1=new Foo();
  Foo obj2=new Foo();
  Foo obj3=new Foo();
  Foo obj4=new Foo();
  System.out.println(obj1.n);
 }

}

原文地址:https://www.cnblogs.com/837634902why/p/7697794.html