Static静态
1.static关键字概述
一旦使用了static关键字,那么这样的内容不再属于对象自己,而是属于类的。
所以凡是本类的对象,都共享同一份
package day08;
public class Student {
private String name;//姓名
private int age;//年龄
static String room;//所在教室
private static int idCounter = 0;//学号计数器,当新建对象时,计数器++
private int id;//学号
public Student() {
this.id = ++idCounter;
}
public Student(String name,int age) {
this.name = name;
this.age = age;
this.id = ++idCounter;
}
public int getId() {
return id;
}
public