title: Java: Inherit constructor
body: <p>I want to have a constructor with an argument that gets inherited by all child classes automatically, but Java won't let me do this</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>class A {
      public A(int x) {
       // Shared code here
      }
  }
  
  class B extends A {
      // Implicit (int x) constructor from A
  }
  
  class C extends A {
      // Implicit (int x) constructor from A
  }
  </code></pre>
  
  <p>I don't want to have to write <code>B(int x)</code>, <code>C(int x)</code>, etc. for each child class. Is there a smarter way of approaching this problem?</p>
  
  <p>Solution #1. Make an <code>init()</code> method that can be called after the constructor. This works, although for my particular design, I want to require the user to specify certain parameters in the constructor that are validated at compile time (e.g. Not through varargs/reflection).</p>