- public enum TrafficLamp{
- RED(30){
- public TrafficLamp nextLamp() {
- return GREEN;
- }
- },
- GREEN(45){
- public TrafficLamp nextLamp() {
- return YELLON;
- }
- },
- YELLON(5){
- public TrafficLamp nextLamp() {
- return RED;
- }
- };
- public abstract TrafficLamp nextLamp();
-
- private int time;
-
- //构造方法
- private TrafficLamp(int time){
- this.time = time;
- }
- }
复制代码 这是枚举中的一段例子~看看能明白不? |