- abstract class Animal
- {
- abstract void eat();
- }
- class Cat extends Animal
- {
- public void eat()
- {
- System.out.println("吃鱼");
- }
- public void catchMouse()
- {
- System.out.println("抓老鼠");
- }
- }
- class Dog extends Animal
- {
- public void eat()
- {
- System.out.println("吃骨头");
- }
- public void kanJia()
- {
- System.out.println("看家");
- }
- }
- public class test {
- public static void main(String[] args) {
-
- function(new Cat());
- function(new Dog());
- function(new Pig());
- }
- public static void function (Animal a)
- {
- a.eat();
- }
-
- }
复制代码 |