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)
* @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)
不是叫cat2吗?