class Animal
{
public void eat()
{
System.out.println("吃食物的方法");
}
}
class Hawks extends Animal
{
public void eat()
{
System.out.println("鹰用嘴雕");
}
}
class frog extends Animal
{
public void eat()
{
System.out.println("青蛙用舌头");
}
}
class locust extends Animal
{
public void eat()
{
System.out.println("蝗虫用群攻");
}
}
class Main
{
public static void main(String[] args)
{
Animal animal = new Hawks();
Hawks hawks1 = (Hawks) animal;
hawks1.eat();
Animal animal1 = new frog();
frog Frog = (frog) animal1;
Frog.eat();
Animal animal2 = new locust();
locust Locust = (locust)animal2;
Locust.eat();
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-1785.html