黑马程序员技术交流社区
标题:
测试题
[打印本页]
作者:
cxl1694095035
时间:
2016-5-17 12:24
标题:
测试题
* 第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;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2