/*
假如我们现在需要对一个系统对员工进行建模
员工包括3个属性:name id 工资
经理也是员工,除了有员工的基本属性之后,还有一个bonus属性
请使用继承的思想设计出员工类和经理类,要求类中必须定义具体的方法供
外部访问
*/
/*问题是:我想在main中获取Pro对象之后,调用 pro.work();但是它显示不能引用父类的私有方法
如果我要在子类中获取到这些属性的话需要怎么做
*/
abstract class Employee
{
private String name;
private String id;
private double sal;
Employee(String name,String id,double sal)
{
this.name = name;
this.id = id;
this.sal = sal;
}
//每个员工都需要进行工作,但是普通员工和经理的工作内容不一样,都是属于员工
public abstract void work();
}
class Manager extends Employee
{
private int bonus;
Manager(String name, String id, double sal, int bonus) {
super(name,id,sal);
this.bonus = bonus;
}
public void work() {
System.out.println("Manager work...");
}
}
class Pro extends Employee
{
Pro(String name, String id, double sal) {
super(name,id,sal);
}
public void work() {
System.out.println("编号:"+id+"名字:"+name+"工资"+sal+":work...");
}
}
public class AbstractTest
{
public static void main(String[] args)
{
Employee pro = new Pro("lisi","开发部-01",8200);
pro.work();
}
}
|