毕老师视频抽象类练习中的源代码
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
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
我想说的是类Employee中有一个抽象方法work(),若要正常编译则应该在类Employee前加abstract关键字修饰...(注意讨论的是加主函数main 的类名后编译产生现象) |