The speed
variable should not be static
. Otherwise it won't be bound to any of the instances of the DynamicObject
class, nor any of it's subclasses instances.
If you want to have a different speed
value for each of the subclasses, you can do:
public class DynamicObject {
protected float speed;
public DynamicObject(float speed) {
this.speed = speed;
}
public float getSpeed() {
return this.speed;
}
}
public class Player extends DynamicObject {
/*some code*/
public Player(float speed) {
super(speed);
}
}
public class Enemy extends DynamicObject {
/*some code*/
public Enemy(float speed) {
super(speed);
}
}