java 枚举

枚举类

public enum

 

枚举元素: 枚举类的一个实例对象

 

复杂的枚举:自由的构造方法.

枚举元素实现一个枚举类的抽象方法

 

 

image

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;
		}
	}
	
	
}
posted @ 2016-08-12 11:58  刘江龙  阅读(251)  评论(0编辑  收藏  举报