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 kanmen()
{
System.out.println("看门");
}
}
class Pig extends Animal
{
public void eat()
{
System.out.println("吃饲料");
}
public void gongdi()
{
System.out.println("拱地");
}
}
class DuotaiDemo
{
public static void main(String[] agrs )
{
chi(new Dog());
}
public static void chi(Animal a)
{
Dog o = (Dog)a;
a.eat(); // 问题在这里!
o.eat();
o.kanmen();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |