I chose this title because I noticed that I did something wrong with the implantation of abstract class but I'm not quite sure what yet.
I created the MoveAble abstract class for training purposes and created the Ball class from it. Also I created a GetPosition() method only for the moveAble class and use it from the ball class. But when I called GetPosition() on any ball object, i got the position varibale of the Moveable Abstract object instead.
I'm guessing its suppose to be that way, but from my understanding we can't use abstract class anyway, so I need to be able to get the position value of the child class even if I implemented this method only on the parents class.
Note: I'm a beginner java programmer. there is probably a better way to do what I did, but that's what I came out with. I would like to hear what you guys think about it, A if you think it's all crooked and there is a better way for all of this I will be glad to learn it.
Moveable class:
public abstract class MoveAble {
private int[] position = new int[2];
private int[] velocity = { 1, 1 };
public int[] getPosition() {
return position;
}
public abstract void move(int width, int height) ;
The ball class:
public class Ball extends MoveAble{
private int[] position = new int[2];
private int[] velocity = { 1, 1 };
public Ball(int x_position, int y_position) {
position[0] = x_position;
position[1] = y_position;
}
@Override
public void move(int width, int height) {
if (position[0] > width - 30 || position[0] < 1) {
velocity[0] *= -1;
}
if (position[1] > height - 30 || position[1] < 1) {
velocity[1] *= -1;
}
position[0] += velocity[0];
position[1] += velocity[1];
}