У меня есть следующий код:<Variable> не может быть решена с переменной
public interface CarInterface {
int getCapacity();
String getCarRegistration();
void setCarRegistration(String registration);
int getFuelAmmount();
boolean isFull();
boolean isRented();
int addLitres(int litres);
int drive();
}
public abstract class Car implements CarInterface{
protected boolean full;
private boolean rented;
private String registration;
protected int fuel;
public String getCarRegistration() {
return registration;
}
public void setCarRegistration(String registration){
this.registration = registration;
}
public int getFuelAmmount() {
return fuel;
}
public boolean isFull() {
return full;
}
public boolean isRented() {
return rented;
}
}
public class LargeCar extends Car{
public int drive() {
return getFuelAmmount();
}
public int addLitres(int litres) {
fuel = fuel + litres;
if (fuel > 65) {
fuel = 65;
}
if (isRented()) {
int x = 5;
}
return x;
}
public int getCapacity() {
return 65;
}
}
Eclipse, говорит мне, что возвращаемый тип несовместим с декларацией интерфейса (Возвращение тип несовместим с CarInterface.addLitres (int)). Я понятия не имею, почему это так. Я сказал, что возвращу int в интерфейсе, и это то, что я делаю ...
У этого также есть проблема с 'x', который, по его словам, не может быть разрешен переменной. Как ни странно, когда я принимаю «int x» из инструкции if, сообщение об ошибке исчезает.
Прохладное форматирование. – ale64bit