- public class Demo
- {
- public static void main(String[] args)
- {
- Animal dog = new Animal()
- {
- public void eat()
- {
- System.out.println("狗吃肉");
- }
- };
-
- Animal cat = new Animal()
- {
- public void eat()
- {
- System.out.println("猫吃鱼");
- }
- };
- dog.eat();
- cat.eat();
- }
- }
- abstract class Animal
- {
- public abstract void eat();
- }
复制代码 |