使用implements关键字与类一起使用接口。
interface Animal {
public void eat();
public void makeSound();
}
class Cat implements Animal {
public void makeSound() {
System.out.println("喵喵");
}
public void eat() {
System.out.println("omnomnom");
}
}
实现接口时,需要重写其所有方法。