import java.io.IOException;
class Text{
public static void main(String[] args) throws IOException{
TrafficLamp lamp=TrafficLamp.RED;
System.out.println(lamp.YELLOW); // 为什么下面会出现黄曲线? 为什么又能运行出结果呢?
System.out.println(lamp.valueOf("YELLOW").name()); //为什么会出现黄曲线?为什么又能运行出结果呢?
System.out.println(lamp.nextLamp());
}
public enum TrafficLamp{
RED(40){
public TrafficLamp nextLamp(){
return GREEN;
};
},GREEN(30){ public TrafficLamp nextLamp(){
return YELLOW;
};
},YELLOW(10){
public TrafficLamp nextLamp(){
return RED;
};
};
public abstract TrafficLamp nextLamp();
private int time;
private TrafficLamp(int time){
this.time=time;
}
}}
|