abstract class Employee
{
private String name;
private String id;
private double pay;
//void Employee(String name,String id,double pay)
//无法将类 Employee中的构造器 Employee应用到给定类型;这里也得用构造函数
Employee(String name,String id,double pay)
{
this.name=name;
this.id=id;
this.pay=pay;
}
public abstract void work();
}
class Manger extends Employee
{
private int bonus;
//public void Manager(String name,String id,double pay,int bonus)
//对super的调用必须是构造器中的第一个语句
//所以你这要用构造函数
Manger(String name,String id,double pay,int bonus)
{
super(name,id,pay);
this.bonus=bonus;
}
public void work()
{
System.out.println("manager work");
}
}
class General extends Employee
{
// public void General(String name,String id,double pay)
General(String name,String id,double pay)// 这里也用构造函数
{
super(name,id,pay);
}
public void work()
{
System.out.println("General work");
}
}
class AbstractTest
{
public static void main(String[] args)
{
General g = new General("zhangsan","9959gy",15895.89);
g.work();
}
}
|