package package1;public class Demo12 {public static void main(String[] args) { javaTeacher javaTeacher=new javaTeacher(20, "张三", 5000); javaTeacher.work(); /* *抽象类不能被实例化 * Employee employee=new Employee(20, "张三", 5000); * */ Leader leader=new Leader(20, "王五", 5000,1000); //向下转型 leader.work(); Employee emp=new Leader(20, "王五", 5000,1000); emp.work();}}//抽象类abstract class Employee{ private int number; private String name; private double salary; public Employee(int number,String name,double salary) { this.name=name; this.number=number; this.salary=salary; } //抽象方法 public abstract void work(); //可实现的方法 public void aa() {} //抽象类中可以有抽象方法也可以有可实现的方法}//一个类继承了抽象类,那么这个类要么实现抽象类中的方法,要么继续抽象下去class Leader extends Employee{ //私有属性 private double allowance;//津贴 public Leader (int number,String name,double salary,double allowance) { super(number, name, salary); this.allowance=allowance; } @Override public void work() { // TODO Auto-generated method stub System.out.println("培训新员工"); System.out.println("设计课程"); } /* *继续抽象下去的表现 * public abstract void work() {} * */}class javaTeacher extends Employee{ public javaTeacher (int number,String name,double salary) { super(number, name, salary); } @Override public void work() { // TODO Auto-generated method stub System.out.println("上java课程"); }}