title: Static fields on a null reference in Java
body: <p><code>static</code> members (<code>static</code> fields or <code>static</code> methods) in Java are associated with their respective class rather than the objects of this class. The following code attempts to access a static field on a <code>null</code> reference.</p>
  
  <pre><code>public class Main
  {
      private static final int value = 10;
  
      public Main getNull()
      {
          return null;
      }
  
      public static void main(String[] args)
      {
          Main main=new Main();
          System.out.println("value = "+main.getNull().value);
      }
  }
  </code></pre>
  
  <p>Although <code>main.getNull()</code> returns <code>null</code>, it works and displays <code>value = 10</code>. How does this code work?</p>