interface Rideable {
String getGait();
}
public class Camel implements Rideable {
int weight = 2;
String getGait() {
return " mph, lope";
}
void go(int speed) {++speed;
weight++;
int walkrate = speed * weight;
System.out.print(walkrate + getGait());
}
public static void main(String[] args) {
new Camel().go(8);
}
}
编译上述代码时,我遇到了一个编译错误,与
getGait()
方法的访问修饰符有关。请解释一下,为什么我应该使用public
访问修饰符声明getGait()
方法?