/*假如我们在开发一个系统时需要对员工进行建模,员工包含3个属性,姓名、工号、以及工资。
经理也是员工,除了含有员工属性外,还有一个奖金属性,请使用继承的思想设计出员工和经理
类。要求类中提供必要的方法进行属性访问*/
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;
System.out.println("姓名:"+this.name+";工号:"+this.id+";工资:"+this.pay);
}
public abstract void work();
}
class Manager extends Employee
{
private int bonus;
Manager(String name,String id,double pay)
{
super(name,id,pay);
}
public void bonus(int bonus)
{
this.bonus=bonus;
System.out.println("奖金:"+this.bonus);
}
public void work()
{
System.out.println("工作内容是:Manager work");
}
}
class Pro extends Employee
{
Pro(String name,String id,double pay)
{
super(name,id,pay);
}
public void work()
{
System.out.println("工作内容是:Pro work");
}
}
class AbstractDemo
{
public static void main(String[] args)
{
Manager m=new Manager("李四","A2015001",5000);
m.bonus(1000);
m.work();
Pro p=new Pro("张三","b2015002",3000);
p.work();
Pro p1=new Pro("杨五","b2015003",3000);
p1.work();
}
}
|
|