A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© cxl1694095035 中级黑马   /  2016-5-17 12:24  /  282 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

         * 第4题:假如我们在开发一个系统时需要对员工进行建模,
         * 员工包含 3 个属性:姓名、工号以及工资。经理也是员工,除了含有员工的属性外,另为还有一个奖金属性。
         * 请使用继承的思想设计出员工类和经理类。要求类中提供必要的方法进行属性访问。
         */
public class Test4 {

        public static void main(String[] args) {

                employee e = new employee("张敏","0027",8000);   
        Manager m = new Manager("李峰","0101",10000,20000);   
            
        System.out.println("员工姓名:"+e.getName()+"\t工号:"+e.getId()+"\t工资:"+e.getMoney());   
        System.out.println("经理姓名:"+m.getName()+"\t工号:"+m.getId()+"\t工资:"+m.getMoney()+"\t奖金:"+m.getBouns());   
        }  
}  
  
class employee  
{  
    private String name;  
    private String id;  
    private long money;  
      
    employee(String name,String id,long money)  
    {  
        this.name = name;  
        this.id = id;  
        this.money = money;  
    }  
  
    public String getName() {  
        return name;  
    }  
  
    public void setName(String name) {  
        this.name = name;  
    }  
  
    public String getId() {  
        return id;  
    }  
  
    public void setId(String id) {  
        this.id = id;  
    }  
  
    public long getMoney() {  
        return money;  
    }  
  
    public void setMoney(long money) {  
        this.money = money;  
    }  
}  
  
class Manager extends employee  
{  
    private double bonus;  
      
    Manager(String name,String id,long money,double bouns)  
    {  
        super(name, id, money);  
        this.bonus = bouns;  
    }  
  
    public double getBouns() {  
        return bonus;  
    }  
  
    public void setBouns(double bouns) {  
        this.bonus = bouns;  
    }  
}  

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马