继承与多态之动手动脑

一、继承条件下的构造方法的调用

class Grandparent { public Grandparent() { System.out.println("GrandParent Created."); } public Grandparent(String string) { System.out.println("GrandParent Created.String:" + string); } } class Parentt extends Grandparent { public Parentt() { super("Hello.Grandparent."); System.out.println("Parent Created"); // super("Hello.Grandparent."); } public Parentt(String s) { System.out.println("Parent Created.String:"+s); } } class Childd extends Parentt { public Childd() { super("Hello.Parent."); System.out.println("Child Created"); } } public class TestInherits { public static void main(String args[]) { Childd c = new Childd(); } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zydwgd.html