抽象类03
编写一个Employee类,声明为抽象类,包含如下三个属性: name, id, salary.提供必要的构造器和抽象方法:work()。对于Manager类来说,他既是员工,还具有奖金(bonus)的属性。请使用继承的思想,设计CommonEmployee类和Manager类,要求类中提供必要的方法进行属性访问,实现work(),提示"经理/普通员工名字工作中.."
package HspAll.Abstract_;
abstract public class Employee {
private String name;
private int id;
private double salary;
public Employee(String name, int id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
//将work做成一个抽象方法
public abstract void work();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
==========
package HspAll.Abstract_;
public class Manager extends Employee{
private double bonus;
public Manager(String name, int id, double salary) {
super(name, id, salary);
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public void work(){
System.out.println("经理"+getName()+"正在工作中....");
}
}
ackage HspAll.Abstract_;
public class EmployCommon extends Employee {
public EmployCommon(String name, int id, double salary) {
super(name, id, salary);
}
@Override
public void work() {
System.out.println("普通员工"+getName()+"正在工作中");
}
}
package HspAll.Abstract_;
public class Exercise {
public static void main(String[] args) {
Manager M1 = new Manager("jack",1234,20000);
M1.setBonus(90000);
M1.work();
}
}