枚举的基本用法
public class test1 { public static void main(String[] args) { //普通使用枚举 System.out.println(Season.spring); //循环遍历枚举里面的值 for (Season season:Season.values()) { System.out.println(season); } System.out.println(Color.white.getxxx()); }}//声明枚举类,可以加访问修饰符enum Season{ //提供当前枚举类的对象 spring, summer, autumn, winter}enum Color{ //必须先声明枚举成员,必须先定义,而且最后要用分号结尾 white("白色"), green("绿色"), pink("粉色"), blue("蓝色"); //声明枚举值的属性 private final String xxx; //还需要构造器 Color(String xxx){ this.xxx=xxx; } //用封装,可以获取xxx的值 public String getxxx(){ return xxx; }}