本帖最后由 董波 于 2013-5-6 11:46 编辑
- abstract class WeekDay{
- private WeekDay(){};
- public final static WeekDay SUN=new WeekDay(){
- public WeekDay nextDay(){
- return MON;//执行该段代码的时候,“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";
- }
- }
- class Test{
- public static void main(String[] args){
- WeekDay weekday=WeekDay.MON;
- System.out.println(weekday.nextDay());
- }
- }
复制代码 问题如代码中所示。
一直对内部类比较困惑,想知道这段代码的执行顺序。求指教。。 |