/* Class name : Fish.java */
interface Fish
{
public void eat();
public void travel();
}
/* Class name : Mammals.java */
interface Mammals
{public void eat();
public void travel();}
/*Amphibians mean living two lives (on land as well as on water). */
/主课/
public class Amphibians implements Mammals,Fish
{
public void eat()
{
System.out.println("Amphibians eating");
}
public void travel()
{
System.out.println("Amphibians traveling");
}
/*Main Method*/
public static void main(String args[])
{
Amphibians a = new Amphibians();
a.eat();
a.travel();
}
}
这里接口在这个类中实现。基本上接口继承两个或多个类,但是这里两个不同的类在同一个方法中使用然后两种方法在一个类中实现。请检查错误正确的代码。