抽象方法只能重写,不能被调用的,在子类中只能调用父类的非抽象方法。抽象方法连方法体都没有,想调用也不行啊。。- public abstract class Horse {
- public void eat() {
- System.out.println("Horse eat");
- }
-
- public abstract void sleep();
- }
- class BlackHorse extends Horse {
- @Override
- public void sleep() {
- System.out.println("Black Horse Sleep!!");
- }
-
- @Override
- public void eat() {
- super.eat();
- System.out.println("Black Horse eat");
- }
-
- public static void main(String[] args) {
- BlackHorse horse = new BlackHorse();
- horse.eat();
- //输出:
- //Horse eat
- //Black Horse eat
- }
- }
复制代码
|