C在(P)的空间和逻辑基础上在Child()构造函数调用下被创建出来,并具有了Child类的其他独有属性和方法,同时将Parent类中需要重写或重载的方法变更,继续占用多出来的空间。 class Grandparent
{
public String str;
public Grandparent()
{
System.out.println(“GrandParent Created.”);
}
public Grandparent(String string)
{
str = string;
System.out.println(“GrandParent Created.String:” + string);
}
}
class Parent extends Grandparent
{
public Parent()
{
super(“Hello.Grandparent.”);
System.out.println(“Parent Created”);
}
}
class Child extends Parent
{
public Child()
{
System.out.println(“Child Created”);
}
}
public class Test
{
public static void main(String args[])
{
Child c = new Child();
System.out.println(c.str);
}
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/220292.html原文链接:https://javaforall.net
