首页 > 其他 > 详细

抽象类

时间:2016-04-16 21:17:26      阅读:144      评论:0      收藏:0      [点我收藏+]
package exer1;
//抽象类的应用
abstract public class TestEmployee {
    public static void main(String[] args) {
        Employee em=new Manager();//多态
        em.work();
        Employee em1=new CommonEmployee();
        em1.work();
    }
}
abstract class Employee{
    private int id;
    private String name;
    private double salary;
    abstract public void work();
    
    public Employee() {
        super();
    }

    public Employee(int id, String name, double salary) {
        super();
        this.id = id;
        this.name = name;
        this.salary = salary;
    }
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    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;
    }

    
}
class Manager extends Employee{
    private double bonus;
    public void work(){
        System.out.println("监督员工");
    }
    public double getBonus() {
        return bonus;
    }

    public void setBonus(double bonus) {
        this.bonus = bonus;
    }
}
//既继承又重写 故是“实体类”可以创建实例
class CommonEmployee extends Employee{
    public void work(){
        System.out.println("在流水线上工作");
    }
}

 

抽象类

原文:http://www.cnblogs.com/alhh/p/5399225.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!