用JAVA定义一个学生类,描述每个学生的编号,姓名,成绩,其中编号为整型,并且按对象创建的顺序自动编号.

如题所述

类加一个静态私有成员, 在构造函数中累加
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;
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答