25 多态

pass。。

public class PoymorphicDemo {
    public static void main(String[] args) {
        Animal a = new Cat();
        a.eat();
    }
}

class Animal {
    public void eat() {
        System.out.println("吃东西");
    }
}

class Cat extends Animal {
    @Override
    public void eat() {
        System.out.println("啃骨头");
    }
}

输出

猜你喜欢

转载自www.cnblogs.com/longesang/p/11234787.html
25
今日推荐