本帖最后由 小马过河 于 2013-11-27 00:02 编辑
问题如下,上面这段代码是测试类,下面那段是创建的类。都是照搬张老师模拟枚举写就的、
问题主要体现在红字部分:因为创建的那个类名是WeekDay1 ,而WeekDay类从哪里而来。这样并没有报错?
这里并没有创建WeekDay类啊。
完整代码中仅仅只有一个地方出现了WeekDay,另一个还是weekDay,W是小写的。其他都是WeekDay1
package Demo_枚举;
public class EnumTest {
public static void main(String[] args) {
WeekDay1 weekDay = WeekDay1.MON;
System.out.println(weekDay.nextDay());
WeekDay WeekDay2 = WeekDay.FRI;
}
public enum WeekDay{——————————————疑问???
SUN,MON,TUE,WED,THI,FRI,SAT;
}
}
********************************************************************************************************************
package Demo_枚举;
public abstract class WeekDay1 {
private WeekDay1(){}
public final static WeekDay1 SUN = new WeekDay1(){
@Override
public WeekDay1 nextDay() {
// TODO Auto-generated method stub
return MON;
}
};
public final static WeekDay1 MON = new WeekDay1(){
@Override
public WeekDay1 nextDay() {
// TODO Auto-generated method stub
return SUN;
}
};
public abstract WeekDay1 nextDay();
public String toString()
return this==SUN?"SUN":"MON";
}
}
|