Search code examples
javavariablesinterfacescopeaccess-modifiers

Why compilation fails? [Java]


interface Rideable {

    String getGait();

}

public class Camel implements Rideable {

    String getGait() { return " mph, lope"; }

}

Why does the compilation fail? I really don't know why the compile error?


Solution

  • By default the modifier for interface's method is public. So when you implement it. It need to be public. Add public to your getGait method should resolve it