本帖最后由 黑龙江—刘鹏 于 2012-7-15 17:07 编辑
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;
} public 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;
}
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 lianxi
{
public static void main(String[] args)
{Manager a=new Manager("liupeng","110",1000,500); }
}
此段如何只改变 class lianxi 类来完成 name id pay bonus的打印呢
如果不能 可以在abstract class Employee类中加上一个打印name id pay的函数就可以了
但是打印bonus的功能难道只能加到class Manager extends Employee类中吗?
能不能通过别的方式实现呢?
|
|