本帖最后由 思维 于 2014-8-17 09:07 编辑
求问:为什么带抽象方法的枚举类enum前面不能用abstract修饰?
- public class EnumTest1{
- public static void main(String[] args){
- TrafficLamp red = TrafficLamp.RED;
- System.out.println(red.nextLamp());
- System.out.println("时间:"+red.time);
- }
- public enum TrafficLamp{
- //REN(){...},GREEN(){...},YELLOW()[...};
- RED(30){
- public TrafficLamp nextLamp(){
- return GREEN;
- }
- },
- GREEN(45){
- public TrafficLamp nextLamp(){
- return YELLOW;
- }
- },
- YELLOW(5){
- public TrafficLamp nextLamp(){
- return RED;
- }
- };
- public abstract TrafficLamp nextLamp();
- private int time;
- private TrafficLamp(int time){this.time = time;}
- }
- }
复制代码 |
|