标签:
枚举类
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; } } }
标签:
原文地址:http://www.cnblogs.com/qq-757617012/p/5764424.html