经理与员工的差异

Employee:

import java.util.Date;
/*
 * 
 */
public class Employee {
    private String name;
    private double salary;
    private Date birthday;
    public Employee(){
        
    }
    public Employee(String name,double salary,Date date){
        this.name=name;
        this.salary=salary;
        this.birthday=date;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getSalary() {
        return salary;
    }
    public void setSalary(double salary) {
        this.salary = salary;
    }
    public Date getBirthday() {
        return birthday;
    }
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

}
View Code

Manager:

public class Manager extends Employee {
    private double bonus;

    public void Manage(Employee em, double bonus) {

    }

    public double getBonus() {
        return bonus;
    }

    public void setBonus(double bonus) {
        this.bonus = bonus;

    }

}
View Code

Test:

import java.util.Date;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
Employee employee=new Employee("java",100,new Date());
System.out.println(employee.getBirthday());
Manager manager=new Manager();
manager.setName("明日科技");
manager.setSalary(3000);
manager.setBirthday(new Date());
manager.setBonus(3000);
System.out.println("員工的姓名"+employee.getName());



    }
}
View Code

 在Manager中并未定义姓名域,可以使用,继承的好处

重点:is_a关系才可以继承,经理显然是员工,所以可以用继承

子类可以是其他类的父亲,构成了一颗继承树,继承树,从上往下看越来越具体,从下往上看,越来越抽象

posted @ 2019-03-30 12:40  Hello_World2020  阅读(370)  评论(0编辑  收藏  举报