class Person{
String name;
int id;
public Person(int id,String name) {
this.name=name;
this.id=id;
}
static int count=0;//count被所有对象共享
{
count++;
}
}
public class Demo46 {
public static void main(String[] args) {
Person p1 = new Person(110,"狗娃1");
Person p2 = new Person(110,"狗娃2");
Person p3 = new Person(110,"狗娃3");
System.out.println("创建对象的个数:"+Person.count);
}
}