本帖最后由 yedong07a 于 2013-5-11 11:45 编辑
public class EnumTest {
public static void main(String[] args) {
System.out.println(TrafficLamp.valueOf("YELLOW").nextLamp());
}
public enum TrafficLamp{
RED(30){
public abstract TrafficLamp nextLamp(){
return GREEN;
}
},
GREEN(45){
public abstract TrafficLamp nextLamp(){
return YELLOW;
}
},
YELLOW(5){
public abstract TrafficLamp nextLamp(){
return RED;
}
};
public abstract TrafficLamp nextLamp();
private int time;
private TrafficLamp(int time){
this.time=time;
}
}
}
枚举,抽象类,构造方法。
|