class Grandparent {public Grandparent() {
System.out.
}
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();
}
}
public為共有類,子繼承父母,父母繼承祖父母
通過 super 調(diào)用基類構(gòu)造方法,必須是子類構(gòu)造方法中的第一個語句。
新聞熱點(diǎn)
疑難解答