interface landAnimal//陆生动物
{
void eat();//动物肯定会吃
void run();//陆生动物肯定会跑
}interface waterAnimal//水生动物
{
void eat();//水里的动物也会吃
void swim();//游泳
}//上面是二个接口
现在有一个青蛙类
class frog extends landAnimal,waterAnimal
{
public void run(){System.out.println("frog can run");}
public void swim(){System.out.println("frog can swim");}
//????????????????????????/
//现在有没有什么办法让我写二个eat方法?
//System.out.println("in water frog can eat something");
//System.out.println("on land frog can eat something ,too");
//C#里,可以这样写
//public void waterAnimal.eat(){console.writeline("in water frog can eat something");}
//public void landAnimal.eat(){console.writeline("on land frog can eat something ,too");}
//但是在JAVA里,为什么我找来找去没有找到合适的方法呢???????????
//呼唤高手赐教!!!!!!!!!!!!!!!!!
}
class frog extends landAnimal,waterAnimal
是不可能的,你只能实现 implements 2个接口!估计是你的笔误!
这两个eat()是没办法区分的
出现这种情况你应该重新考虑下接口的涉及
比如定义一个Animal接口,里面有一个eat()方法
再定义两个接口分别extends Animal接口(接口entends接口,而不是implements)
这两个eat()是没办法区分的
出现这种情况你应该重新考虑下接口的涉及
比如定义一个Animal接口,里面有一个eat()方法
再定义两个接口分别extends Animal接口(接口entends接口,而不是implements)