• 对象下—练习2


    Employee.java

    package com.atguigu.exer1;
    /*
     * 编写一个Employee类,声明为抽象类,
    包含如下三个属性:name,id,salary。
    提供必要的构造器和抽象方法:work()。
     * 
     * 
     */
    public abstract class Employee {
    	
    	private String name;
    	private int id;
    	private double salary;
    	public Employee() {
    		super();
    	}
    	public Employee(String name, int id, double salary) {
    		super();
    		this.name = name;
    		this.id = id;
    		this.salary = salary;
    	}
    	
    	public abstract void work();
    }
    
    

    EmployeeTest.java

    package com.atguigu.exer1;
    /*
     * 请使用继承的思想,设计CommonEmployee类和Manager类,要求类中提供必要的方法进行属性访问。
     */
    public class EmployeeTest {
    	public static void main(String[] args) {
    		
    		//多态
    		Employee manager = new Manager("库克", 1001, 5000, 50000);
    		
    		manager.work();
    		
    		CommonEmployee commonEmployee = new CommonEmployee();
    		commonEmployee.work();
    		
    	}
    }
    
    

    Menager.java

    package com.atguigu.exer1;
    /*
     * 对于Manager类来说,他既是员工,还具有奖金(bonus)的属性。
     */
    public class Manager extends Employee{
    	
    	private double bonus;//奖金
    
    	
    	
    	public Manager(double bonus) {
    		super();
    		this.bonus = bonus;
    	}
    
    	public Manager(String name, int id, double salary, double bonus) {
    		super(name, id, salary);
    		this.bonus = bonus;
    	}
    
    	@Override
    	public void work() {
    		System.out.println("管理员工,提供公司运行的效率");
    	}
    	
    	
    	
    }
    
    

    CommonEmployee.java

    package com.atguigu.exer1;
    
    public class CommonEmployee extends Employee {
    
    	@Override
    	public void work() {
    		System.out.println("员工在一线车间生产产品");
    	}
    
    }
    
  • 相关阅读:
    娃娃机 解题报告
    ecshop
    多字节字符串 函数
    电商中设置满包邮,满减等促销搞活动;电商平台同步到第三方,日志记录
    PHP文件操作
    apache重写字段详细说明
    httpc服务器错误类型大全
    正则入门简易
    php100 编程小技巧
    memcache
  • 原文地址:https://www.cnblogs.com/fenxiangyuan/p/14397146.html
Copyright © 2020-2023  润新知