title: java initialize base class fields in subclass constructor
body: <p>This is a very basic question about subclasses in java, I still don't get it...</p>
  
  <p>Suppose I have a superclass with three fields and with only the default constructor:</p>
  
  <pre><code>public class Superclass {
      public int a;
      public int b;
      public int c;
  }
  </code></pre>
  
  <p>and I want to add a field x. I cannot change <code>Superclass</code>, so I make a subclass:</p>
  
  <pre><code>public class Subclass extends Superclass {
      public int x;
      public Subclass(Superclass s) {
          super();
          // what to do??
      }
  }
  </code></pre>
  
  <p>I now want to generate a <code>Subclass</code> object from an existing <code>Superclass</code> object:</p>
  
  <pre><code>Superclass s = new Superclass();
  s.a = "a";
  s.b = "b";
  Subclass sc = new Subclass(s);
  sc.x = "x";
  </code></pre>
  
  <p>such that I can still access <code>sc.a</code>, <code>sc.b</code> etc.</p>
  
  <p>How can I best do this without assigning all these fields 'by hand' in the constructor of the subclass?</p>