我正在尝试实现这样的接口:
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();
}
}但它会显示错误:
Ame和Chin talk()无法实现Human talk()。
Methods is overridden as static . 请告诉我为什么会发生这种情况,以及如何修复这个错误。
发布于 2016-07-28 13:05:37
不能以这种方式从静态方法引用非静态接口。本质上,静态方法是可以直接访问的方法,而不需要重新创建本地重复对象,但不能以相同的方式修改它的值。真的,这个问题的解决方案很简单。从覆盖talk()方法中删除静态修饰符
https://stackoverflow.com/questions/38627378
复制相似问题