10.22 继承条件下的构造方法调用 代码部分: package lianxi; public class bo { public static void main(String[] args) { Child c = new Child(); } } class Grandparent { public Grandparent() { System.out.println("GrandParent Crea
10.22
继承条件下的构造方法调用
代码部分:
package lianxi;public class bo {
public static void main(String[] args) {
Child c = new Child(); }
}
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"); }
}
运行结果:
运行结果分析;
先构造基类构造方法再构造子类构造方法