I have an interface WithNaturalCoordinates with method setX and a class that implements it (RepetitiveRobotImpl). That class (RepetitiveRobotImpl) also extends a class called Robot.
Robot also has a method setX.
Now my question is, how do I implement the method setX without overriding the setX from Robot?
My interface:
public interface WithNaturalCoordinates {
void setX(int x);
}
The class Robot:
public void setX(int x) {
world.trace(this, RobotAction.SET_X);
setXRobot(x);
}
The class which implements the interface:
public class RepetitiveRobotImpl extends Robot implements WithNaturalCoordinates {
public RepetitiveRobotImpl(int numberOfRepetitions){
super(0, 0, Direction.UP, 100);
}
public void setX(int x) {
if(x < 0) {
super.setX(-x);
}
else {
super.setX(x);
}
}
Here the method setX is kinda doing both implementing and overriding.
Sorry, if it sounds kinda weird, I'm new to Java & programming in general.