标签:
1 public class Test5 { 2 3 /** 4 * @throws InterruptedException 5 */ 6 public static void main(String[] args) throws InterruptedException { 7 Deng[] deng = Deng. values(); 8 for( int i = 0;i < 3;i++){ 9 Deng d = deng[i]; 10 if(d == Deng. red){ 11 System. out.println(d); 12 Thread. sleep(5000); 13 System. out.println(d.next()); 14 } else if(d == Deng. green){ 15 Thread. sleep(3000); 16 System. out.println(d.next()); 17 } else if(d == Deng. yellow){ 18 Thread. sleep(2000); 19 // System.out.println(d.next()); 20 i = -1; 21 } 22 } 23 } 24 } 25 enum Deng{ 26 red("红灯"){ 27 public Deng next(){ 28 return green; 29 } 30 },green("绿灯"){ 31 public Deng next(){ 32 return yellow; 33 } 34 },yellow("黄灯"){ 35 public Deng next(){ 36 return red; 37 } 38 }; 39 public abstract Deng next(); 40 private String name; 41 private Deng(String name){ 42 this. name = name; 43 } 44 @Override 45 public String toString() { 46 return name; 47 } 48 }
标签:
原文地址:http://www.cnblogs.com/junzhao/p/4852424.html