为什么不行啊- abstract class Animal
- {
- public abstract void eat();
- }
- class Cat extends Animal
- {
- public void eat()
- {
- System.out.println("chiyu");
- }
- public void catchMouse()
- {
- System.out.println("zhualaoshu");
- }
- }
- class DuoTaiDemo1
- {
- public static void main(String[] args)
- {
-
- Animal a=new Animal();
- Cat c = (Cat)a;这样不可以,将父类对象转成子类类型
- c.eat();
-
- }
- }
复制代码 |