本帖最后由 杨兴庭 于 2013-8-1 18:46 编辑
public abstract class WeekDay {
private WeekDay() {
}
public static final WeekDay SUN = new WeekDay() {
public WeekDay nextDay() {
return MON;
}
};
public static final WeekDay MON = new WeekDay() {
public WeekDay nextDay() {
return SUN;
}
};
public abstract WeekDay nextDay();
/*
* public WeekDay nextDay(){ if(this==SUN) return MON; else return SUN; }
*/
public String toString() {
return (this == SUN) ? "SUN" : "MON";
}
}
这个类中有抽象方法,必须要定义成抽象的类,但是为什么在枚举中定义了抽象方法,但是为什么就不用定义成抽象的呢??
public enum trafficLamp {
RED {
public trafficLamp nextLamp() {
return null;
}
},
GREEN {
public trafficLamp nextLamp() {
return null;
}
},
YELLOW {
public trafficLamp nextLamp() {
return null;
}
};
public abstract trafficLamp nextLamp();
}
难道这就是类和枚举的区别吗?
请大家指教!
|