【java基础增强】带抽象方法的枚举

时间:2023-02-17 11:37:42
import org.junit.Test;

public class Demo2 {

@Test
public void test(){
print(Grade.B);
}

public void print(Grade g){
String value=g.localValue();
System.out.println(value);
}

enum Grade{

A("100-90"){
public String localValue(){
return "优";
}
},
B("89-80"){
public String localValue(){
return "良";
}
},
C("79-70"){
public String localValue(){
return "一般";
}
},
D("69-60"){
public String localValue(){
return "及格";
}
},
E("59-0"){
public String localValue(){
return "差";
}
};

private String value;
//定义私有构造方法
private Grade(String value){
this.value=value;
}

public String getValue(){
return this.value;
}

public abstract String localValue();
}
}