这是一段Java代码:
interface Rideable {
String getGait();
}
public class Camel implements Rideable {
int x = 2;
public static void main(String[] args) {
new Camel().go(8);
}
void go(int speed) {
System.out.println((++speed * x++) + this.getGait());
}
String getGait() {
return " mph, lope";
}
}
事实证明,编译失败(根据Oracle),尽管我认为编译会很好地产生输出。那么,编译失败的罪魁祸首在哪里?
干杯
最佳答案
您无法降低所覆盖方法的可见性(接口(interface)方法默认为public
),请尝试以下方法:
public String getGait() {
return " mph, lope";
}
关于java - 编译失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13671951/