我想实现这样的接口:为什么我的界面方法不能被覆盖?
public interface Human{
void talk();
}
public class Ame implements Human{
public static void talk(){
System.out.println("Speak English");
}
}
public class Chin implements Human{
public static void talk(){
System.out.println("Speak Chinese");
}
}
public class test {
public static void main(String[] args){
Chin c = new Chin();
c.talk();
Ame a = new Ame();
a.talk();
}
}
但它显示错误:
阿梅和Chin谈()无法实现人的谈话()。
方法被重写为静态。
请告诉我为什么发生这种情况,以及如何解决这个错误。
为什么你要使用静态方法? – John3136
您不能拥有同名和签名的静态和非静态方法。而静态方法不会实现该接口。 – Thilo
我只是好奇为什么人类的谈话()不能被重写为静态谈话()。 – AngusMurphy