- package com.hspedu.abstractUse;
-
- public class abstractUse {
- public static void main(String[] args) {
- Manager xiaohong = new Manager("小红", "222131", 2000);
- xiaohong.work();
- xiaohong.setBonus(8000);
- // long start = System.currentTimeMillis();
- // System.out.println(start);
- }
- }
-
- abstract class Employee {
- private String name;
- private String id;
- private double salary;
-
- public Employee(String name, String id, double salary) {
- this.name = name;
- this.id = id;
- this.salary = salary;
- }
- public abstract void work();
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public double getSalary() {
- return salary;
- }
-
- public void setSalary(double salary) {
- this.salary = salary;
- }
- }
-
- class Manager extends Employee {
- private double bonus;
-
- public Manager(String name, String id, double salary) {
- super(name, id, salary);
- }
-
- public double getBonus() {
- return bonus;
- }
-
- public void setBonus(double bonus) {
- this.bonus = bonus;
- }
-
- @Override
- public void work() {
- System.out.println("经理 " + getName() + "正在工作中");
- }
- }
-
- class commonEmployee extends Employee {
- public commonEmployee(String name, String id, double salary) {
- super(name, id, salary);
- }
-
- @Override
- public void work() {
- System.out.println("员工 " + getName() + "正在工作中");
- }
- }
抽象的使用细节