//类名包名省略。。
@Test
public void test6() {
//枚举
print(Grade.B);
print2(Grade2.B);
}
public void print(Grade g){
System.out.println(g);
}
public void print2(Grade2 g){
System.out.println(g.getVale());
}
enum Grade{
A,B,C,D//ABCD均为Grade的四个对象 Object型
}
/* 下面的这写注释内容相当于上面3行代码
* static class Grade{
private Grade(){
}
public static final Grade A =new Grade();
public static final Grade B =new Grade();
public static final Grade C =new Grade();
public static final Grade D =new Grade();
}*/
enum Grade2{
A("90-100"),B("80-90"),C("70-80"),D("60-70");//ABCD分别代表这不懂分段的分值。因为没有写无参构造方法所以ABCD对象后要传值
String value2;
private Grade2(String value){
this.value2=value;
}
public String getVale(){
return value2;
}
}
运行结果