title: Java Instance Initialization Block and instance variables
body: <p>In context to my previous question <a href="https://stackoverflow.com/questions/24895489/java-classes-and-static-blocks">Java classes and static blocks</a> what if I changed my code from static block and variables to normal Instance Initialization Block and instance variables. Now how would the code be executed?</p>
  
  <pre><code>class extra3 {
      public static void main(String string[]) {
          Hello123 h = new Hello123();
          System.out.println(h.a);
      }
  }
  class Hello123 {
      {
          a=20;
      }
      int a=158;
  }
  </code></pre>
  
  <p>Here I am getting output as 158. I am not able to understand the reason here.And the other code being this:</p>
  
  <pre><code>class extra3 {
      public static void main(String string[]) {
          Hello123 h = new Hello123();
          System.out.println(h.a);
      }
  }
  class Hello123 {
      int a=158;
      {
          a=20;
      }
  }
  </code></pre>
  
  <p>Here the output is 20 which is acceptable because when object is created Instance block is executed first. But why is the output in first code coming as 158?</p>