title: Initialize superclass variables (needed in constructor) in a subclass
body: <p>I'm writing a simple Asteroids-clone game, using <code>Swing</code> to display the graphics. I'm kind of following <a href="https://www.youtube.com/playlist?list=PLE7E8B7F4856C9B19" rel="nofollow noreferrer">Derek Banas' tutorials</a>, but decided to expand on my own.</p>
  
  <p>The original idea is that every graphic element in the game (i.e. the Asteroids, the Spaceship and the Bullets) extends the <code>Polygon</code> class. Their constructor would look something like this:</p>
  
  <pre><code>public class SpaceShip extends Polygon {
  
      //x and y coordinates
      public static int[] polyXArray = {...};
      public static int[] polyYArray = {...};
  
      //other class variables
      {...}
  
      public SpaceShip() {
  
          super(polyXArray, polyYArray, polyXArray.length);
      }
  }
  </code></pre>
  
  <p>And it will be similar for the other graphic elements.</p>
  
  <p>EDIT: The key element here is that the two arrays don't store the actual coordinates of the objects, but their position relative to their centre, whose coordinates are <code>double</code>-type class-variable. Thus, the arrays describe just the <em>shape</em> of the object, while the subclass <code>move()</code> method will affect the centre's coordinates. The class responsible for the actual drawing will call the <code>move()</code> method and then apply an affine transform to move and rotate the shape (according to a properly defined angle parameter). I'm doing this to avoid precision problems related to dealing with <code>double</code> arithmetic.</p>
  
  <p>Now, since the elements share a lot of "equal" variables (their centre coordinates, which I need in order to translate them with an affine transform, their speed components etc...) and methods (getters and setters, <code>move()</code> methods, etc...) I thought about making them be the extension of an abstract class - say, <code>GameShape</code> - which holds all these common methods and variables. <code>GameShape</code> would now be the one extending <code>Polygon</code> directly:</p>
  
  <pre><code>public abstract class GameShape extends Polygon {
  
          //x and y coordinates, still unassigned
          public static int[] polyXArray, polyYArray;
  
          //other class variables
          {...}
  
          public GameShape() {
  
              super(polyXArray, polyYArray, polyXArray.length);
          }
  }
  </code></pre>
  
  <p>Then, I'd want to assign the desired value to <code>polyXArray</code> and <code>polyYArray</code> when I define the different subclasses in order to draw the different shapes I need, but I haven't been able to find a way to do it.</p>
  
  <p>I do want those variable to be static because they are specific properties of the single classes, and I wouldn't want to pass them as a parameter every time I instantiate a new object.</p>
  
  <p>My situation is very similar to the one described in <a href="https://stackoverflow.com/questions/14076730/java-initializing-superclass-variables-in-subclasses">this question</a>, but the proposed solution doesn't seem to work, since I need those very variables in the constructor. Is there a way to get over - or around - this problem? Regardless of the procedure, my main aim is to have a superclass common to all the graphic elements, in order to avoid tens of lines of copy-pasted code. </p>