Why is NullPointerException in Java?

Java 8Object Oriented ProgrammingProgramming

NullPointerException is a runtime exception and it is thrown when the application try to use an object reference which has a null value.

For example, using a method on a null reference.

Object ref = null;
ref.toString(); // this will throw a NullPointerException
Published on 07-Feb-2018 10:09:49