I want to get x with getX method and use it in other class, but eclipse says that my method should be static, but I don't want to make it static.
public abstract class Shape {
private int x;
private Color color;
public Shape (int x, Color color) {
this.x = x;
this.color = color;
}
public abstract void draw();
public Color getColor() {
return color;
}
public int getX() { //here here here
return x;
}
}
public class Square extends Shape {
public Square(int x, Color color) {
super(x, color);
}
public void draw() {
for(int i = 0; i < Shape.getX(); i++) {// here is a problem
System.out.print(" ");
}
if (getColor() == Color.BLACK)
System.out.println("[]");
if (getColor() == Color.RED)
System.err.println("[]");
}
}
I want to make it executable.