package cn.itcast;
import java.util.Date;
public class EnumTest {
public static void main(String[] args) {
WeekDay weekday1 = WeekDay.MON;
//System.out.println(weekday1.nextDay());
//System.out.println(weekday);
WeekDay weekDay2 = WeekDay.FRI;
System.out.println(weekDay2);
System.out.println(weekDay2.name());
System.out.println(weekDay2.ordinal());
System.out.println(WeekDay.valueOf("SUN").toString());
System.out.println(WeekDay.values().length);
new Date(300){};
}
public enum WeekDay{
//构造方法必须写在枚举元素之后
//如果在枚举元素之后没有写括号,默认调用的是无参构造
//枚举的构造方法必须是private类型的
//如果在枚举元素之后带括号,这时调用的是有参构造。
SUN(),MON(),TUE(),WED,THT,FRI,SAT;
private WeekDay(){
System.out.println("first");
}
private WeekDay(int day){
System.out.println("second");
}
}
public enum TrafiicLamp{
RED(30) {
public TrafiicLamp nextLamp() {
return GREEN;
}
},
GREEN(45) {
public TrafiicLamp nextLamp() {
return YELLOW;
}
},
YELLOW(5) {
public TrafiicLamp nextLamp() {
return RED;
}
};
public abstract TrafiicLamp nextLamp();
private int time;
private TrafiicLamp(int time){
this.time = time;
}
}
}