- package com.itcast.test3_2;
- abstract class Animal{
- String name;
- int age;
- void run(){
- System.out.println("run()");
- }
- abstract void eat();
- }
- class Dog extends Animal{
- //重写父类的抽象方法
- void eat(){
- System.out.println("吃骨头");
- }
- }
- class Cat extends Animal{
- //重写父类的抽象方法
- void eat(){
- System.out.println("吃鱼");
- }
- }
- public class Demo {
- public static void main(String[] args) {
-
- }
- }
复制代码 |