public class EnumTest { enum Enum { //定义常量 spring(1,"春天好呀"), summer(2,"夏天贼热"), autumn(3,"秋天凉爽"), winer(4,"冬天冻死"); private final int code; private final String desc; Enum(int code,String desc){ this.code = code; this.desc = desc; } public int getCode(){ return code; } public String getDesc(){ return desc; } } public static void main(String[] args) { System.out.println("序号"+Enum.spring.getCode()+" 描述:" + Enum.spring.getDesc()); System.out.println("序号"+Enum.summer.getCode()+" 描述:" + Enum.summer.getDesc()); System.out.println("序号"+Enum.autumn.getCode()+" 描述:" + Enum.autumn.getDesc()); System.out.println("序号"+Enum.winer.getCode()+" 描述:" + Enum.winer.getDesc()); } }
枚举类型是指由一组固定的常量组成合法的类型,由 enum 关键字来定义一个枚举类型。