Write a code to show NullPointerException

Write a code to show NullPointerException

Approach

Java


import java.util.List;

public class TryCatch1 {
    public static void main(String[] args) {
        try {
            List<Integerl = null;
            System.out.println(l.get(2));
        } catch (IndexOutOfBoundsException | NullPointerException e) {
            System.out.println("Exception is " + e);
        }
    }
}


No comments:

Post a Comment