日期:2014-05-18  浏览次数:20684 次

java小程序,多态报错
package com.wangsufu;

public class Doutai_2 {

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
Master master = new Master();

master.feed(new Cat(), new Fish());


}

}
class Animal
{
public void eat()
{
System.out.println("不知道吃啥");
}

}

class Cat2 extends Animal{

public void eat()
{
System.out.println("猫吃鱼!");
}

}


class Dog2 extends Animal
{
public void eat()
{
System.out.println("狗吃骨头!");
}
}

class Food{

public void showname()
{
System.out.println("...");

}

}

class Bone extends Food
{
public void showname()
{
System.out.println("我是骨头");

}
}

class Fish extends Food
{
public void showname()
{
System.out.println("我是鱼");

}
}

class Master{

public void feed(Animal an,Food f)
{
f.showname();
an.eat();

}
}
报错如下:
The method feed(Animal, Food) in the type Master is not applicable for the arguments (Cat, Fish)



------解决方案--------------------
哪了你的cat类了?哪了你的dog类了?
不是叫cat2吗?