public static final NanChang Spring= new NanChang("春天","春暖花开");
// 先定义枚举类的属性
private final String SeasonName ;
private final String Season;
// 构造器私有化 为属性赋值
private NanChang(String seasonName,String season){
this.SeasonName=seasonName;
this.Season=season;
}
// 定义枚举类的对象
public String getSeasonName() {
return SeasonName;
}
public String getSeason() {
return Season;
}
@Override
public String toString() {
return "NanChang{" +
"SeasonName='" + SeasonName + '\'' +
", Season='" + Season + '\'' +
'}';
}
枚举类的写法(自定义枚举类,和使用 enum关键字)
最新推荐文章于 2023-09-04 10:09:39 发布