关键字
public class Demo02 {
public static void main(String[] args) {
System.out.println(Season.SPRING);
}
}
enum Season {
SPRING("春天"),SUMMER("夏天");
private String name;
private Season(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Season{" +
"name='" + name + '\'' +
'}';
}
}
import javax.swing.*;
public class Demo02 {
public static void main(String[] args) {
System.out.println(Season.SPRING);
Season [] seasons = Season.values();
for (Season season :seasons) {
System.out.println(season);
}
System.out.println(Season.SPRING.name());
System.out.println(Season.SPRING.ordinal());
System.out.println(Season.SPRING.compareTo(Season.SUMMER));
}
}
enum Season {
SPRING("春天"),SUMMER("夏天");
private String name;
private Season(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Season{" +
"name='" + name + '\'' +
'}';
}
public class Demo03 {
public static void main(String[] args) {
System.out.println("星期信息如下:");
Week [] weeks = Week.values();
for (Week week:weeks){
System.out.println(week);
}
}
}
enum Week{
MONDAY("星期一"),TUESDAY("星期二"),WEDNESDAY("星期三"),
THURSDAY("星期四"),FRIDAY("星期五"),SATURDAY("星期六"),SUNDAY("星期天");
private String name;
private Week(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
- enum 关键字修饰的类 底层是一个final修饰的 继承 enum的类,所以不能再继承其他类,可以实现接口欧