- abstract class Employee
- {
- private String name;
- private String id;
- private double pay;
- Employee(){} [color=Red]//这条注释掉就会出现错误[/color]
- Employee(String name,String id,double pay)
- {
- this.name=name;
- this.id=id;
- this.pay=pay;
- }
- public abstract void work();
- }
- class Manager extends Employee //经理类
- {
- //super(); 这里省略了这条语句,子类初始化时默认调用父类中空参数构造函数,如果你改成super(String name,String id,double pay),那么就没问题了
- private int bonus;
- Manager(){}
- Manager(String name,String id,double pay,int bonnus)
- {
- super(name,id,pay);
- this.bonus=bonus;
- }
- public void work()
- {
- System.out.println("Manager work");
- }
- }
- class Pro extends Employee //普通员工类
- {
- Pro(){}
- Pro(String name,String id,double pay)
- {
- super(name,id,pay);
- }
- public void work()
- {
- System.out.println("Pro work");
- }
- }
- class AbstractTest
- {
- public static void main(String[] args)
- {
- new Manager().work();
- Pro p=new Pro();
- p.work();
- }
- }
复制代码 |