title: Java static final field initialization order
body: <p>I tried to understand the behavior of initialization order when static fields are initialized with a reference to the same enclosing class object.   </p>
  
  <pre><code>public class Test {
  
          static final Test t=new Test();
          static int a=5;
  
          Test(){
              System.out.println("a="+a);
          }
  
          public static void main(String[] args) {
              new Test();
          }
  
      }
  </code></pre>
  
  <p>Output of above piece of code is:</p>
  
  <pre><code>a=0
  a=5
  </code></pre>
  
  <p>If I modify variable <code>a</code> to anything else other than plain <code>static</code>:</p>
  
  <pre><code>static final a=5;
  a=5;
  final a=5;
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>a=5
  a=5
  </code></pre>
  
  <p>Why is this behavior?</p>
  
  <p>Note that the output is <code>a=5 &amp; a=5</code> even when both <code>t &amp; a</code> are declared as <code>static final</code> in which case <code>t</code> precedes the declaration of <code>a</code></p>