继承与接口动手动脑

源代码:
class Grandparent {

    public Grandparent() 

   {

     System.out.println("GrandParent Created.");
   }

   public Grandparent(String string)
   {
     System.out.println("GrandParent Created.String:" + string);
   }

}


class Parent extends Grandparent {

    public Parent()

   {
   //super("Hello.Grandparent.");
   System.out.println("Parent Created");
  // super("Hello.Grandparent.");
   }

}


class Child extends Parent {

   public Child()
  {
     System.out.println("Child Created");
  }

}


public class TestInherits {

   public static void main(String args[])
  {
     Child c = new Child();
  }
}

super是第一句

不是第一句

结论:

有继承类的情况下,在进行方法调用或函数构造时系统会先构造基类在构造父类最后在构造子类

通过super语句调用基类构造函数,必须放在子类构造方法中的第一句。

 

posted @ 2015-11-08 14:27  岩蔷薇之简  阅读(98)  评论(0编辑  收藏  举报