/*** @Author Helius* @Create 2019-05-19-21:48*/
public class SeasonTest {public static void main(String[] args) {Season spring = Season.SPRING;System.out.println(spring);}
}/*** 自定義枚舉類*/
class Season {// 1.聲明season對象的屬性,private,final修飾private final String seasonName;private final String seasonDesc;// 2.私有化類的構造器private Season(String seasonName, String seasonDesc) {this.seasonName = seasonName;this.seasonDesc = seasonDesc;}// 3.提供當前枚舉類的多個對象:public static final的public static final Season SPRING = new Season("春天","春暖花開");public static final Season SUMMER = new Season("夏天","夏日炎炎");public static final Season AUTUMN = new Season("秋天","秋高氣爽");public static final Season WINTER = new Season("冬天","冰天雪地");// 4.獲取枚舉類對象的屬性public String getSeasonName() {return seasonName;}public String getSeasonDesc() {return seasonDesc;}//5.提供toString()@Overridepublic String toString() {return "Season{" +"seasonName='" + seasonName + '\'' +", seasonDesc='" + seasonDesc + '\'' +'}';}
}