类加一个静态私有成员, 在构造函数中累加
public class Student {
private static int _number = 1;
private int number;
public String name;
public double point;
public Stedunt() {
this.number = Student._number;
Student ._number++;
}
//number只读
public int getNumber() {
return this.number;
}
}
温馨提示:内容为网友见解,仅供参考