java中的抽象类与抽象方法

public class Test {
    public static void cheshi(Animal a){
        a.run();
    }
    public static void main(String[] args) {
        cheshi(new bird());
        cheshi(new dog());
        cheshi(new fish());
    }
}
abstract class Animal{
    abstract  void run();
}
class bird extends Animal{
    void run(){
        System.out.println("起飞");
    }

}
class dog extends Animal{
    void run(){
        System.out.println("奔跑");
    }
}
class fish extends Animal{
    void run(){
    System.out.println("游泳");
}
}

你可能感兴趣的:(java,servlet,jvm)