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
}
Khi tôi cố gắng biên dịch DerivedClass
nó mang lại cho tôi những lỗigiao diện và thừa kế: "kiểu trả về int không tương thích"
java: myMethod() in interfaceRnD.DerivedClass cannot override myMethod() in interfaceRnD.SuperClass return type int is not compatible with java.lang.String
Làm thế nào tôi nên giải quyết vấn đề này?
bây giờ nó nghe có vẻ thú vị – Xinus
Vậy là có thực sự điều gì sai với 'public String myMethod() {...} '? Từ sự hiểu biết của tôi, vấn đề duy nhất là dòng ngay sau đó. Tôi đã bỏ lỡ một cái gì đó? – Josay