本帖最后由 沐阳6011 于 2014-6-4 11:22 编辑
- abstract class Employee
- {
- private String name;
- private String id;
- private double pay;
- Employee(String name,String id,double pay)
- {
- this.setName(name);
- this.setId(id);
- this.setpay(pay);
- }
- public void setName(String name) //设置姓名
- {
- this.name=name;
- }
- public String getName() // 获得姓名
- {
- return name;
- }
- public void setId(String id) //设置编号
- {
- this.id=id;
- }
- public String getId() //获得编号
- {
- return id;
- }
- public void setPay(double pay) //获得编号
- {
- this.pay=pay;
- }
- public double getPay() //获得工资
- {
- return pay;
- }
- public abstract void work();
- public void display()// 显示雇员的信息;
- {
- System.out.println(name+","+id+","+pay);
- }
- }
- class Pro extends Employee
- {
- Pro(String name,String id,double pay)
- {
- super(name,id,pay);
- }
- public void work()
- {
- System.out.println("Pro working");
- }
- }
- class Manager extends Employee
- {
- private double bonus;
- Manager(String name,String id,double pay,double bonus)
- {
- super(name,id,pay);
- this.bonus= bonus;
- }
- public void work()
- {
- System.out.println("Manager working");
- }
- public void display()
- {
- System.out.println(super.getName()+","+super.getId()+","+super.getPay()+","+this.bonus);
- /*System.out.println(super.display()+","+this.bonus);*/
- }
-
- }
- class AbstractTest2
- {
- public static void main(String[] args)
- {
- Manager mJoker = new Manager("Mjokers","M001",8000,10000);
- mJoker.work();
- mJoker.display();
- }
- }
复制代码
这个代码是正确的,但是注释中的内容替换了它上一条输出语句就会报错。super可以调用父类中的get函数,为什么不能调用display函数。错误提示是:super.display(),此处不允许使用空类型。这是怎么回事,两个函数都是空参的啊?
求懂的哥们们指教一下。:):) |
|