看下面的代码:
package logan.study.learn; public class Parent { private int data; public Parent(int d){ data = d; } }
package logan.study.learn; public class Child extends Parent { String name; public Child(String s,int d){ _____________ name = s; } }
答案是:
package logan.study.learn; public class Child extends Parent { String name; public Child(String s,int d){ super(d); name = s; } }
1.子父类存在同名成员时,子类中默认访问子类的成员,可通过super指定访问父类的成员,格式:super.xx (注:xx是成员名);
2.创建子类对象时,默认会调用父类的无参构造方法,可通过super指定调用父类其他构造方法,格式:s uper(yy) (注:yy是父类构造方法需要传递的参数)