• 经理与员工的差异


    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关系才可以继承,经理显然是员工,所以可以用继承

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

  • 相关阅读:
    第2课 C 到 C++ 的升级
    第1课 学习 C++ 的意义
    归并排序
    插入排序与希尔排序
    选择排序
    冒泡排序
    CodeSignal 刷题 —— almostIncreasingSequence
    CodeSignal 刷题 —— matrixElementSum
    Python3 序列解包
    单星号变量(*)和双星号变量(**)的用法
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/10626491.html
Copyright © 2020-2023  润新知