title: Facing Problem with order of execution of constructor static block and code block
body: <p>I knew that when i create an instance static block first initialized then code block and then constructor here my code</p>
  <pre><code>public class Main{
  
  public Main() {
      out.println(&quot;constructor initialised&quot;);
  }
  
  static {
      out.println(&quot;static block initialised&quot;);
  }
  {
      out.println(&quot;Code block initialised&quot;);
  }
  
  public static void main(String... args) {
  
      new Main();
  }
  
  }
  </code></pre>
  <p>output like this</p>
  <p>static block initialised<br>
  Code block initialised<br>
  constructor initialised<br></p>
  <p>the output above clear my concept but when I extend some class like this</p>
  <pre><code>public class Main extends Bear{
  
  public Main() {
      out.println(&quot;constructor initialised&quot;);
  }
  
  static {
      out.println(&quot;static block initialised&quot;);
  }
  {
      out.println(&quot;Code block initialised&quot;);
  }
  
  public static void main(String... args) {
      new Main();
  }
  }
  </code></pre>
  <p>Bear Class</p>
  <pre><code>class Bear{
  static {
      out.println(&quot;static block initialised of bear class&quot;);
  }
  
  {
      System.out.println(&quot;Code bLock initialised of bear class&quot;);
  }
  
  void run() {
      out.println(&quot;running...&quot;);
  }
  }
  </code></pre>
  <p>output like this:</p>
  <p>static block initialised of bear class<br>
  static block initialised<br>
  Code bLock initialised of bear class<br>
  Code block initialised<br>
  constructor initialised<br></p>
  <p>when extending class the order of execution is changed i don't understand why this was happens the output above</p>