1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| public class SeasonTest1 { public static void main(String[] args) { Season1 summer = Season1.SUMMER; System.out.println(summer.toString());
System.out.println("****************"); Season1[] values = Season1.values(); for(int i = 0;i < values.length;i++){ System.out.println(values[i]); values[i].show(); } System.out.println("****************"); Thread.State[] values1 = Thread.State.values(); for (int i = 0; i < values1.length; i++) { System.out.println(values1[i]); }
Season1 winter = Season1.valueOf("WINTER");
System.out.println(winter); winter.show(); } }
interface Info{ void show(); }
enum Season1 implements Info{ SPRING("春天","春暖花开"){ @Override public void show() { System.out.println("春天在哪里?"); } }, SUMMER("夏天","夏日炎炎"){ @Override public void show() { System.out.println("宁夏"); } }, AUTUMN("秋天","秋高气爽"){ @Override public void show() { System.out.println("秋天不回来"); } }, WINTER("冬天","冰天雪地"){ @Override public void show() { System.out.println("大约在冬季"); } };
private final String seasonName; private final String seasonDesc;
private Season1(String seasonName,String seasonDesc){ this.seasonName = seasonName; this.seasonDesc = seasonDesc; }
public String getSeasonName() { return seasonName; }
public String getSeasonDesc() { return seasonDesc; }
}
|