// 定义的枚举类默认继承于java.lang.Enum
public class enumTest {
public static void main(String[] args) {
Season spring = Season.SPRING;
System.out.println(spring); // SPRING
}
}
enum Season {
// 1. 提供当前枚举类的对象,多个对象直接用逗号,末尾用分号结束
SPRING("春天", "春暖花开"),
SUMMER("夏天", "夏日炎炎"),
AUTUMN("秋天", "秋高气爽"),
WINTER("冬天", "冰天雪地");
// 2. 声明Season对象的属性:private final 修饰
private final String seasonName;
private final String seasonDesc;
// 3. 私有化类的构造器
private Season(String seasonName, String seasonDesc) {
this.seasonName = seasonName;
this.seasonDesc = seasonName;
}
// 4.获取枚举类对象的属性
public String getSeasonName() {
return seasonName;
}
public String getSeasonDesc() {
return seasonDesc;
}
}