枚举类也是一个类,当其中定义了一个抽象的方法时,为什么不用abstract修饰呢?- public enum TrafficLamp {
- RED(30){
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return GREEN;
- }
-
- },
- GREEN(45){
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return YELLOW;
- }},
- YELLOW(5){
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return RED;
- }
-
- };
- public abstract TrafficLamp nextLamp();//抽象方法
- private int time;
- private TrafficLamp(int time){this.time = time;}
-
- }
复制代码 详细说明一下哈。
|