// 枚举:
// 给别人固定范围的选择题
enum Grade { //class
A, B, C, D, E; // Object
}
// 等效于:
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();
public static final Grade E = new Grade();
}
===============================
含有抽象方法的枚举:
//抽象类枚举
package day01;
import org.junit.Test;
public class EnumDemo2 {
@Test
public void test(){
print(Grade2.B);
}
public void print(Grade2 g){
String value = g.loclaValue();
System.out.println(value);
}
}
enum Grade2{
//注意格式!!!
A("100-90"){
public String loclaValue(){
return "优";
};
}
,B("89-80"){
public String loclaValue(){
return "良";
};
}
,C("79-70"){
public String loclaValue(){
return "中";
};
}
,D("69-60"){
public String loclaValue(){
return "及格";
};
}
,E("59-0"){
public String loclaValue(){
return "不及格";
};
};;
private String value ;
private Grade2 (String value){
this.value = value;
}
public abstract String loclaValue();
}