title: Why are member objects initialized after the super class's constructor?
body: <p>I ran into an interesting problem yesterday and while the fix was quite simple, I'm still a bit fuzzy on the "why" of it.  </p>
  
  <p>I have a class that has a private member variable that is assigned when it is instantiated, however if it is used in an abstract function that is called by the super class's constructor, the variable does not have a value.  The solution to the problem was quite simple, I simply had to declare the variable as <em>static</em> and it was assigned correctly.  Some code to illustrate the problem:</p>
  
  <pre><code>class Foo extends BaseClass
  {
      private final String bar = "fooBar!";
      public Foo()
      {
          super();
      }
  
      @Override 
      public void initialize()
      {
          System.out.println(bar);
      }
  }
  </code></pre>
  
  <p>And the base class:</p>
  
  <pre><code>abstract class BaseClass
  {
      public BaseClass()
      {
          initialize();
      }
  
      public abstract void initialize();
  }
  </code></pre>
  
  <p>In this example, when we call <code>new Foo();</code> it will output <em>(null)</em> instead of the expected <em>fooBar!</em></p>
  
  <p>Since we're instantiated an object of type Foo, should its members not be allocated and assigned prior to calling its (and consequently its super class's) constructor?  Is this specified somewhere in the Java language or is it JVM specific?</p>
  
  <p>Thanks for any insight!</p>