枚舉類
public enum
枚舉元素: 枚舉類的一個實例對象
復雜的枚舉:自由的構造方法.
枚舉元素實現一個枚舉類的抽象方法
package test; public class TestEnum { public static void main(String[] args) { Triffic tr=Triffic.GREEN; System.out.println(tr+" 下一個燈是: "+tr.nextDeng()); } public enum Triffic{ RED (400){ @Override public Triffic nextDeng() { return GREEN; } }, GREEN (200){ @Override public Triffic nextDeng() { return YELLOW; } }, YELLOW(10) { @Override public Triffic nextDeng() { return RED; } }; public abstract Triffic nextDeng(); int time; private Triffic(int time){ this.time=time; } public int getTime() { return time; } public String toString(){ return this.name()+":"+this.time; } } }