title: What happens when subclasses don't define a constructor in Java?
body: <p>I have a few cases I wonder about. First, if you have no constructor:</p>
  
  <pre><code>class NoCons { int x; }
  </code></pre>
  
  <p>When I do <code>new NoCons()</code>, the default constructor gets called. What does it do exactly? Does it set <code>x</code> to 0, or does that happen elsewhere?</p>
  
  <p>What if I have this situation:</p>
  
  <pre><code>class NoCons2 extends NoCons { int y; }
  </code></pre>
  
  <p>What happens when I call <code>new NoCons2()</code>? Does <code>NoCons</code>'s default constructor get called, and then <code>NoCons2</code>'s constructor? Do they each set the respective <code>x</code> and <code>y</code> fields to 0?</p>
  
  <p>What about this version:</p>
  
  <pre><code>class Cons2 extends NoCons { int y; public Cons2() {} }
  </code></pre>
  
  <p>Now I have a constructor, but it doesn't call the super class's constructor. How does <code>x</code> ever get initialized? What if I had this situation: </p>
  
  <pre><code>class Cons { int x; public Cons() {} }
  class NoCons2 extends Cons { int y;  }
  </code></pre>
  
  <p>Will the <code>Cons</code> constructor be called?</p>
  
  <p>I could just try all these examples, but I can't tell when a default constructor is run. What's a general way to think about this so that I'll know what happens in future situations? </p>