image.png

    1. package com.atguigu.exercise1;
    2. public abstract class Employee {//雇员
    3. //属性
    4. private String name;
    5. private int id;
    6. private int salary;//工资
    7. //构造器
    8. public Employee(){
    9. }
    10. public Employee(String name,int id,int salary){
    11. this.name = name;
    12. this.id = id;
    13. this.salary = salary;
    14. }
    15. //方法
    16. public abstract void work();
    17. }

    1. package com.atguigu.exercise1;
    2. public class Manager extends Employee{//管理人员,经理
    3. private int bonus;//奖金
    4. //构造器
    5. public Manager(){
    6. }
    7. public Manager(int bonus){
    8. this.bonus = bonus;
    9. }
    10. public Manager(int bonus,String name,int id,int salary){
    11. super();
    12. this.bonus = bonus;
    13. }
    14. @Override
    15. public void work() {
    16. System.out.println("管理员工");
    17. }
    18. }

    1. package com.atguigu.exercise1;
    2. public class CommonEmployee extends Employee{//普通员工
    3. @Override
    4. public void work() {
    5. System.out.println("员工在一线生产产品");
    6. }
    7. }

    1. package com.atguigu.exercise1;
    2. public class EmployeeTest {
    3. public static void main(String[] args) {
    4. //多态
    5. Employee manager = new Manager(5000,"Tom",1001,50000);
    6. manager.work();
    7. CommonEmployee commonEmployee = new CommonEmployee();
    8. commonEmployee.work();
    9. }
    10. }