枚举
1.枚举的引入
需求分析
要求创建季节Season对象,设定季节名称和描述,并完成春夏秋冬四个季节的初始化。最原始的做法定义一个Season,然后分别定义4个季节对象
public class Season {
public String name;
public String descr;
Season(String name, String descr) {
this.name = name;
this.descr = descr;
}
public static void main(String[] args) {
Season spring = new Season("spring", "春天来了");
Season summer = new Season("summer", "夏天好热");
Season autumn = new Season("autumn", "秋分凉爽");
Season winter = new Season("winter", "一夜入冬");
}
}
...大约 4 分钟