-5
public class Abc
{
   public static void main(String args[])
   {
      def obj=null;
      obj.method();
    }
}
class Def
{
   void method()
   {
       System.out.println("class def->>> method()");
   }
}

The output of this code is generating a NullPointerException and why?

Lokesh
  • 29
  • 1
  • 5
  • please read the javadoc for `NullPointerException`. https://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html – Jos May 16 '16 at 08:17

1 Answers1

0

The NullPointerException means you tried to deference a null value so you get the expected behaviour.

It doesn't have anything to do with detecting uninitialised values. It's not called UninitialisedException

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130