package com.user.test3;
public class Manager extends Employee {
private double bonus;
public Manager(double bonus) {
super();
this.bonus = bonus;
}
public Manager(String name, int id, double salary, double bonus) {
super(name, id, salary);
this.bonus = bonus;
}
@Override
public String toString() {
return "姓名:" + getName() + "\tID:" + getId() + "\tsalary:" + getSalary() + "\tbonus:" + bonus;
}
@Override
public void work() {
// TODO Auto-generated method stub
System.out.println("管理人员");
}
}
package com.user.test3;
public class CommonEmployee extends Employee {
private double bonus;
public CommonEmployee(double bonus) {
super();
this.bonus = bonus;
}
public CommonEmployee(String name, int id, double salary, double bonus) {
super(name, id, salary);
this.bonus = bonus;
}
@Override
public String toString() {
return "姓名:" + getName() + "\tID:" + getId() + "\tsalary:" + getSalary() + "\tbonus:" + bonus;
}
@Override
public void work() {
// TODO Auto-generated method stub
System.out.println("普通人员");
}
}
package com.user.test3;
public abstract class Employee {
private String name;
private int id;
private double salary;
public Employee() {
super();
}
public Employee(String name, int id, double salary) {
super();
this.name = name;
this.id = id;
this.salary = salary;
}
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;
}
public abstract void work();
}
package com.user.test3;
import org.junit.Test;
public class EmployTest {
@Test
public void testEmplyee() {
Employee m = new Manager("張三",1001,2000,8000);
Employee c = new CommonEmployee("李三",1002,2000,3000);
m.work();
c.work();
System.out.println(m.toString());
System.out.println(c.toString());
}
}
控制台输出:
管理人员
普通人员
姓名:張三 ID:1001 salary:2000.0 bonus:8000.0
姓名:李三 ID:1002 salary:2000.0 bonus:3000.0