I've learned all these programming terms in Swedish so please bear with me..
I'm having problems calling a method in a subclass which should override a method in the superclass.
Here is the class structure with removed code:
public interface Movable {
public void move(double delta);
}
public abstract class Unit implements Movable, Viewable{
public void move(double delta){
System.out.println("1");
}
}
public class Alien extends Unit{
public void move(long delta){
System.out.println("2");
}
}
public class Player extends Unit{
public void move(long delta){
System.out.println("3");
}
}
public void main(){
ArrayList<Unit> units = new ArrayList<Unit>();
Unit player = new Player();
Unit alien = new Alien();
units.add(player);
units.add(alien);
for (int i = 0; i < this.units.size(); i++) {
Unit u = (Unit) this.units.get(i);
u.move();
}
}
This would output 1 and 1, but I want it to output 2 and 3.
What am I doing wrong? I thought this was how it worked.