本帖最后由 蓝色的枫叶 于 2012-7-12 09:52 编辑
在覆盖toString方法时,会报错:返回值类型应该是String类型。
不知道哪里错了。在覆盖toString() 方法时有特殊的格式么?
请帮解答下,谢谢了
package cn.xushuai.day1;
public class Enum {
public static void main(String[] args){
WeekDay Monday = WeekDay.MON;
WeekDay Tueday = WeekDay.TUE;
System.out.println(Monday.nextDay());
System.out.println(Tueday.nextDay());
}
package cn.xushuai.day1;
public abstract class WeekDay {
private WeekDay(){}
public abstract WeekDay nextDay();
public final static WeekDay MON = new WeekDay(){
public WeekDay nextDay(){
return TUE;
}
};
public final static WeekDay TUE = new WeekDay(){
public WeekDay nextDay(){
return WED;
}
};
@Override
public String toString(){
if (this==MON)
return "MON";
else if (this==TUE)
return "TUE";
}
}
|