Generate Null Pointer exception in java

Write a program to generate Null Pointer exception in java.

package Exception_demo;

import java.util.*;
public class exception_2
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
            String s1=null;
            System.out.println(s1.length());
    }    
}

Leave a Reply

Your email address will not be published. Required fields are marked *