带抽象方法的枚举

import org.junit.Test;

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

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

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();
}

你可能感兴趣的:(带抽象方法的枚举)