title: static variable initialization java
body: <p>how to initialize a private static member of a class in java.</p>
  
  <p>trying the following:</p>
  
  <pre><code>public class A {
     private static B b = null;
     public A() {
         if (b == null)
           b = new B();
     }
  
     void f1() {
           b.func();
     }
  }
  </code></pre>
  
  <p>but on creating a second object of the class A and then calling f1(), i get a null pointer exception.</p>