因为变量定义了private,所以我的思路是用get、set,通关后查看了答案,又发现super关键字中新大陆
掌握知识点- super关键字
- 类的继承
- 重写父类方法时,可在方法中直接调用父类
class Employee {
private String name;// 员工姓名
private String birth;// 出生年月
private String position;// 职位
// 使用有参构造方法初始化Employee
public Employee(String name, String birth, String position) {
this.name = name;
this.birth = birth;
this.position = position;
}
public void introduction() {
System.out.println("员工姓名:" + name + "n出生年月:" + birth + "n职位:" + position);
}
}
public class Salary extends Employee {
private double salary; // 薪水
// 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码
// 定义Salary的有参构造方法,同时在子类中指代父类构造器
public Salary(String name,String birth,String positon,double salary){
super(name,birth,positon);
this.salary = salary;
}
public void introduction(){
super.introduction(); //直接用super调用父类方法,然后再重写
System.out.println("薪水:" + salary);
}
}



