17.抽象实例
假如我们在开发一个系统时需要对员工进行建模,员工包含3个属性:姓名、工号和工资。
经理也是员工,除了含有员工的属性外,另外还有一个奖金属性,请使用继承的思想设计出员工类和经理类。
要求类中提供必要的方法进行属性访问
员工类:name id pay
经理类:继承了员工,并有自己特有的bonus
public class Abstract_07 { public static void main(String[] args) { // TODO Auto-generated method stub } } abstract class Employee{ private String name; private String id; private double pay; Employee(String name,String id,double pay){ this.name=name; this.id=id; this.pay=pay; } abstract void work(); } class Manager extends Employee{ private int bonus; Manager(String name,String id,double pay,int bonus){ super(name,id,pay); this.bonus=bonus; } @Override void work() { // TODO Auto-generated method stub System.out.println("manager work"); } } class Normal extends Employee{ Normal(String name, String id, double pay) { super(name, id, pay); // TODO Auto-generated constructor stub } @Override void work() { // TODO Auto-generated method stub System.out.println("normal work"); } }