原理
class Grade{
private String level;
//私有化
private Grade(){}
private Grade(String level){
this.level = level;
}
public static Grade A = new Grade("90-100");
public static Grade B = new Grade("80-90");
public static Grade C = new Grade("70-80");
public static Grade D = new Grade("60-70");
public static Grade E = new Grade("<60");
}
枚举
// jdk5.0以后
enum Grade{
A("90-100"),B("80-90"),C("70-80"),D("60-70"),E("<60");
private String level;
private Grade(){}
private Grade(String level){
this.level = level;
}
}