Java abstract 小测试

 1 package com.bytezreo.abstractTest;
 2 
 3 /**
 4  * 
 5  * @Description   abstract 小测试
 6  * @author Bytezero·zhenglei!        Email:420498246@qq.com
 7  * @version
 8  * @date 下午9:25:10
 9  * @
10  *
11  */
12 public class EmployeeTest {
13     public static void main(String[] args) {
14         
15         
16         //多态
17         Employee manger = new Manger("Tom",1001,2000,5000);
18         
19         manger.work();
20         
21         CommonEmployee commonEmployee = new CommonEmployee();
22     
23         commonEmployee.work();
24     }
25 }
 1 package com.bytezreo.abstractTest;
 2 
 3 /**
 4  * 
 5  * @Description   
 6  * @author Bytezero·zhenglei!        Email:420498246@qq.com
 7  * @version
 8  * @date 下午9:11:25
 9  * @
10  *
11  */
12 public abstract class Employee {
13 
14     private String name;
15     private int id;
16     private double salary;
17     
18     public Employee() {
19         super();
20     }
21     public Employee(String name, int id, double salary) {
22         super();
23         this.name = name;
24         this.id = id;
25         this.salary = salary;
26     }
27     
28     public abstract void work();
29     
30     
31     
32     
33 }
 1 package com.bytezreo.abstractTest;
 2 
 3 public class Manger extends Employee {
 4     
 5     private double bonus;    //奖金
 6     
 7 
 8     public Manger(double bonus) {
 9         super();
10         this.bonus = bonus;
11     }
12 
13 
14     public Manger(String name, int id, double salary, double bonus) {
15         super(name, id, salary);
16         this.bonus = bonus;
17     }
18 
19     @Override
20     public void work() {
21         System.out.println("管理员工,提高公司运行效率");
22         
23     }
24     
25     
26     
27 }
 1 package com.bytezreo.abstractTest;
 2 
 3 public class CommonEmployee extends Employee {
 4 
 5     
 6     @Override
 7     public void work() {
 8         System.out.println("生产产品");
 9         
10     }
11 
12 }

 

posted on 2021-10-04 21:34  Bytezero!  阅读(65)  评论(0)    收藏  举报