title: When do instance variables get initialized and values assigned?
body: <p>When does the instance variable get initialized? Is it after the constructor block is done or before it?</p>
  <p>Consider this example:</p>
  <pre><code>public abstract class Parent {
  
   public Parent(){
     System.out.println(&quot;Parent Constructor&quot;);
     init();
   }
  
   public void init(){
     System.out.println(&quot;parent Init()&quot;);
   }
  }
  </code></pre>
  <hr />
  <pre><code>public class Child extends Parent {
  
  private Integer attribute1;
  private Integer attribute2 = null;
  
  public Child(){
      super();
      System.out.println(&quot;Child Constructor&quot;);
  }
  
  public void init(){
      System.out.println(&quot;Child init()&quot;);
      super.init();
      attribute1 = new Integer(100);
      attribute2 = new Integer(200);
  }
  
  public void print(){
      System.out.println(&quot;attribute 1 : &quot; +attribute1);
      System.out.println(&quot;attribute 2 : &quot; +attribute2);
  }
  }
  </code></pre>
  <hr />
  <pre><code>public class Tester {
  
  public static void main(String[] args) {
      Parent c = new Child();
      ((Child)c).print();
      
  }
  }
  </code></pre>
  <hr />
  <h1>OUTPUT:</h1>
  <p>Parent Constructor</p>
  <p>Child init()</p>
  <p>parent Init()</p>
  <p>Child Constructor</p>
  <p>attribute 1 : 100</p>
  <p>attribute 2 : null</p>
  <hr />
  <ol>
  <li><p>When are the memory for the atribute 1 &amp; 2 allocated in the heap ?</p>
  </li>
  <li><p>Curious to know why is attribute 2 is NULL ?</p>
  </li>
  <li><p>Are there any design flaws?</p>
  </li>
  </ol>