Why it throws null pointer exception when object is initialized to null and then trying to access class method? : <pre><code>public class Abc
{
   public static void main(String args[])
   {
      def obj=null;
      obj.method();
    }
}
class Def
{
   void method()
   {
       System.out.println("class def-&gt;&gt;&gt; method()");
   }
}
</code></pre>

<p>The output of this code is generating a NullPointerException and why?</p>
