public class Test1 {
public static void main(String[] args){
Staff em=new Staff("小李","www333",1000);
Manager ma=new Manager("王经理","www999",3000);
System.out.println("Staff:"+em.getSalary());
System.out.println("Manager:"+ma.getSalary(2000));
}
}
public class Staff {
//定义员工类
//设置员工的三个属性为私有
private String name;
private String number;
private double Salary;
//设置三个属性的set和get方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public double getSalary() {
return Salary;
}
public void setSalary(double Salary) {
this.Salary = Salary;
}
//定义员工的构造函数
public Staff (String name,String number,double Salary){
this.name=name;
this.number=number;
this.Salary=Salary;
}
}
class Manager extends Staff {//定义经理类继承员工类
public double award;
public Manager(String name, String number, double Salary) {
super(name, number, Salary);
}
public double getSalary(double award){
return super.getSalary()+award;
}
}
|
|