标签:定义类 不能 枚举 ring private string ati 使用 打印
public class Season {
private Season() {}//使此类不能被new
public static final Season SPRING = new Season();
public static final Season SUMMER = new Season();
public static final Season FALL = new Season();
public static final Season WINTER = new Season();
}
public class Main {
public static void main(String[] args) {
Season s = Season.SPRING;
if(s==Season.SPRING){
System.out.println("春天");
}else if (s==Season.SUMMER){
System.out.println("夏天");
}else if (s==Season.FALL){
System.out.println("秋天");
}else if(s==Season.WINTER){
System.out.println("冬天");
}
}
}
public class Main {
public static void main(String[] args) {
Season s = Season.WINTER;
//打印枚举的名称 WINTRE
System.out.println(s.name());
//打印枚举的索引 3
System.out.println(s.ordinal());
}
public enum Season {
SPRING,SUMMER,FALL,WINTER
}
}
标签:定义类 不能 枚举 ring private string ati 使用 打印
原文地址:https://www.cnblogs.com/xl4ng/p/12663078.html