zoukankan      html  css  js  c++  java
  • 抽象类

    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("在流水线上工作");
        }
    }
  • 相关阅读:
    2019/9/8
    实现简单的网页登录注册功能 (使用html和css以及javascript技术) 没有美化的日后补全
    测试一些以前的代码
    使用三层开发遵循的原则
    超市管理
    热身训练
    考试第三题
    考试第七题
    考试第10题
    考试第8题
  • 原文地址:https://www.cnblogs.com/alhh/p/5399225.html
Copyright © 2011-2022 走看看