public enum TrafficLamp{
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;}
}
RED,GREEN,YELLOW是TrafficLamp的3个对象对吧?因为里面有抽象方法,那么RED等3个对象应该是TrafficLamp子类的对象啊,可是为什么这里这么写? |