Skip to main content

Write a java Program to raise NullPointerException

· One min read
Kaustubh Kulkarni
nullPointer.java
public class nullPointer {  
public static void main(String[] args) {
Object ref = null;
ref.toString();
}
}


Output:

  
LENOVO@DESKTOP-U7S0DTI MINGW64 /e/H-drive/Practicals/MCA/SEM III/JAVA/Practicals/assignment no1
$ java null_pointer.java
Exception in thread "main" java.lang.NullPointerException
at nullPointer.main(null_pointer.java:11)