public abstract class WeekDay
{
private WeekDay(){} //构造方法私有化,避免建立对象
public final static WeekDay SUN=new WeekDay(){
public WeekDay nextDay()//覆盖父类的抽象方法,建立子类对象调用
{
return MON;
}
};
public final static WeekDay MON=new WeekDay(){
public WeekDay nextDay()
{
return SUN;
}
};
public abstract WeekDay nextDay();
public String toString()
(
return this==SUN?"SUN":"MON";
)
}
public class EnumTest
{
public static void main(String[] args)
{
WeekDay weekDay=WeekDay.MON;
System.out.println(weekDay.nextDay());
}
}