- abstract class Animal
- {
-
- public abstract void eat();
-
- public void sleep()
- {
- System.out.println("所有动物都要睡觉");
-
- }
- }
- class Cat extends Animal
- {
- public void eat()
- {
-
- System.out.println("猫要吃鱼");
-
- }
- public void sleep()
- {
-
- System.out.println("猫是最爱睡觉的动物");
-
- }
- public void Catmouse()
- {
-
- System.out.println("猫要抓老鼠");
- }
-
- }
- class Dog extends Animal
- {
- public void eat()
- {
- System.out.println("狗要吃肉");
-
- }
-
-
- }
- class Pig extends Animal
- {
-
- public void eat()
- {
- System.out.println("猪要吃玉米");
-
- }
-
-
- }
- public class Duotai
- {
- public static void main(String[] args)
- {
-
- function(new Cat());
- Animal a = new Cat();
-
- Cat c = (Cat) a;
- a.eat();
- a.sleep();
- c.Catmouse();
-
- }
- public static void function(Animal a)
- {
- a.eat();
-
-
-
-
- }
-
-
-
- }
复制代码 |
|