在程序中声明一个表示雇员的类Employee。在类Employee中声明两个成员变量,分别表示雇员的姓名和薪酬。声明类Employee构造方法,声明设置和获取成员变量值的成员方法。 声明一个部门经理类Manager,Manager继承自Employee。在Manager中增加表示部门经理奖金的成员变量。声明类Manager的构造方法,声明设置和获取成员变量值的成员方法。 在程序的主类PayrollApp中创建一个Manager类的对象,对其进行初始化,并且在控制台输出它的成员变量的值
时间: 2024-03-01 07:55:16 浏览: 273
以下是Java代码实现:
```
public class Employee {
private String name;
private double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
public class Manager extends Employee {
private double bonus;
public Manager(String name, double salary, double bonus) {
super(name, salary);
this.bonus = bonus;
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
}
public class PayrollApp {
public static void main(String[] args) {
Manager manager = new Manager("Tom", 5000, 1000);
System.out.println("Name: " + manager.getName());
System.out.println("Salary: " + manager.getSalary());
System.out.println("Bonus: " + manager.getBonus());
}
}
```
输出结果为:
```
Name: Tom
Salary: 5000.0
Bonus: 1000.0
```
阅读全文