标签:
//打印特定的值; public class Demo1 { public void test(){ print(Grade.A); } public void print(Grade grade){//打印特定的值; String value=grade.localValue(); System.out.println(value); } /* * 方法一 static class Grade{ public Grade(){} private static final Grade A =new Grade(); private static final Grade B=new Grade(); private static final Grade C=new Grade(); private static final Grade D=new Grade(); } */ //方法二 enum Grade{ //定义了A的值在什么到什么之间; 把A BCD 四个看成是四个Grade对象 A("100-90"){//要把抽象方法实现 public String localValue(){ return "优"; } },B("90-80"){ public String localValue(){ return "中"; } },C("80-70"){ public String localValue(){ return "良"; } },D("70-0"){ public String localValue(){ return "一般"; } }; private String value; private Grade(String value) { this.value = value; } public String getValue(){ return value; } public abstract String localValue();//显示的是可以自己定义的方法 } }
标签:
原文地址:http://www.cnblogs.com/JohnChen-happy/p/4336067.html