个人理解:首先这不是一个枚举,该类没有用enum修饰。
而该类就好比给WeekDay定义了两个子类,Mon和Sun,在创建这两个子类的时候通过匿名内部类复写nextDay()方法
感觉这像一个自定义的枚举
我写了一个常规的枚举
public enum WeekDay {
SUN()
{
public WeekDay nextDay()
{
return MON;
}
},
MON()
{
public WeekDay nextDay()
{
return TUE;
}
},
TUE()
{
public WeekDay nextDay()
{
return WEN;
}
},
WEN()
{
public WeekDay nextDay()
{
return THU;
}
},
THU()
{
public WeekDay nextDay()
{
return FRI;
}
},
FRI()
{
public WeekDay nextDay()
{
return SAT;
}
},
SAT()
{
public WeekDay nextDay()
{
return SUN;
}
};
private WeekDay(){}
public abstract WeekDay nextDay();
}
public static void main(String[] args) {
WeekDay weekday = WeekDay.SAT;
System.out.println(weekday.nextDay());
} |