摘要:
注:方法覆盖要求子类与父类的方法一模一样,否则就是方法重载(overload) 测试: 1. 在子类中,若要调用父类中被覆盖的方法,可以使用super关键字。 package test2; class Grandparent { public Grandparent() { System.out.p 阅读全文
摘要:
为什么子类的构造方法在运行之前,必须调用父类的构造方法?能不能反过来?为什么不能反过来? 构造方法的主要作用为在创建类对象时,对其实例化,对其中的数据进行初始化,如果子类的构造方法在运行之前,不调用父类的构造方法,则子类继承自父类的成员无法进行初始化,不能反过来,因为父类没有继承子类成员,没有子类成 阅读全文
摘要:
package test2; class Grandparent { public Grandparent() { System.out.println("GrandParent Created."); } public Grandparent(String string) { System.out 阅读全文
