public class EmployeeDemo {
public static void main(String[] args) {
JavaTeacher teacher=new JavaTeacher(1,"大白",5555);
teacher.work();
Leader leader =new Leader(2,"小黑",6666,10000);
leader.work();
}
}
//抽象类
abstract class Employee{
private int number;
private String name;
private double salary;
public Employee(int number,String name,double salary){
this.number=number;
this.name=name;
this.salary=salary;
}
//抽象方法的声明
public abstract void work();
}
//一旦一个类去继承了抽象类,那么这个类要么实现抽象类中的抽象
//方法,要么被定义成抽象类
class JavaTeacher extends Employee{
public JavaTeacher(int number,String name,double salary){
super(number,name,salary);
}
public void work(){
System.out.println("上Java课");
}
}
class Leader extends Employee{
private double allowance;//津贴
public Leader (int number,String name,double salary,double allowance){
super(number,name,salary);
this.allowance=allowance;
}
public void work(){
System.out.println("培训新员工");
System.out.println("设计课程体系");
}
}
继承抽象方法的子类必须重写该方法。否则,该子类也必须声明为抽象类。最终,必须有子类来实现该抽象方法,否则,从最终的父类到最终的子类都不能用来实例化对象.