Posted on 2017-04-07 11:19
朱杰兵 阅读(88)
评论(0) 编辑 收藏
public enum MessageLevel {
LOW {
@Override
public String getDesc() {
return "低";
}
@Override
public String getCode() {
return "L";
}
@Override
public String getIcon() {
return "medal_bronze_1.png";
}
},
HEIGH {
@Override
public String getDesc() {
return "高";
}
@Override
public String getCode() {
return "H";
}
@Override
public String getIcon() {
return "medal_gold_1.png";
}
},
NORMAL {
@Override
public String getDesc() {
return "中";
}
@Override
public String getCode() {
return "N";
}
@Override
public String getIcon() {
return "medal_silver_1.png";
}
};
public abstract String getDesc();
public abstract String getCode();
public abstract String getIcon();
}
- public static void main(String[] args)
- {
- System.out.println(MessageLevel.LOW.getDesc());
- System.out.println(MessageLevel.LOW.getCode());
System.out.println(MessageLevel.LOW.getIcon());
- }
-----------------------------------------------------------------------------------------------
- public enum Operation
- {
- PLUS
- {
- public double eval(double x,double y)
- {
- return x+y;
- }
- },
- MINUS
- {
- public double eval(double x,double y)
- {
- return x-y;
- }
- },
- TIMES
- {
- public double eval(double x,double y)
- {
- return x*y;
- }
- },
- DIVIDE
- {
- public double eval(double x,double y)
- {
- return x/y;
- }
- };
- //为枚举类定义一个抽象方法,这个抽象方法由不同的枚举值提供不同的实现。
- public abstract double eval(double x,double y);
- public static void main(String[] args)
- {
- System.out.println(Operation.PLUS.eval(3,4));
- System.out.println(Operation.MINUS.eval(5,4));
- System.out.println(Operation.TIMES.eval(5,4));
- System.out.println(Operation.DIVIDE.eval(5,4));
- }
- }