public interface MyInterface{
public int myMethod();
}
public class SuperClass {
public String myMethod(){
return "Super Class";
}
}
public class DerivedClass extends SuperClass implements MyInterface {
public String myMethod() {...} // this line doesn't compile
public int myMethod() {...} // this is also unable to compile
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,DerivedClass它给了我错误
java: myMethod() in interfaceRnD.DerivedClass cannot override myMethod() in interfaceRnD.SuperClass return type int is not compatible with java.lang.String
我该如何解决这个问题?