通过super关键访问父类被重写的方法
super.成员变量
super.成员方法([实参列表])
在子类构造方法中调用父类构造方法 应使用super关键字
super([参数列表])
参数列表为传入的值
class parent{
String name;
public parent(String name){
==this.name = name;==
System.out.println("调用有参构造方法");
}
public void say() {
System.out.println("父辈");
}
}
class child extends parent{
public child(){
==super("par");==
}
public void say() {
System.out.print("姓名:"+name);
}
}
public class Text {
public static void main(String[] args) {
child c =new child();
c.say();
}
}
结果
调用有参构造方法
姓名:par
实例化子类对象时,首先调用父类构造方法,再调用子类的构造方法,