Super不要在Super构造器中调用覆盖方法

import java.util.Date;


public class Super{
   public Super(){
             System.out.println("5");
      overrideMe();
             System.out.println("6");
   }
   public void overrideMe(){}
}

public final class Sub extends Super
{
   private final Date date;
   Sub(){
      date=new Date();
       System.out.println("1");
   }

   @Override public void overrideMe()
   {
      System.out.println(date);
   }

   public  static void main(String[] args)
   {
      Sub sub=new Sub();
             System.out.println("2");
      sub.overrideMe();
             System.out.println("3");
   }
}


----------------------------------------
5
null
6
1
2
Wed Mar 30 10:55:31 SGT 2016
3
----------------------------------------

 

posted on 2016-03-30 10:56  rojas  阅读(207)  评论(0编辑  收藏  举报