Syntax error Why is NullPointerException in Java?

Why is NullPointerException in Java?



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
Updated on: 2020-02-25T05:02:26+05:30

293 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements