ExamVeda
Login
Home
This question belongs to Java Program Exceptions
Exceptions
?

Predict the output:
public class Test{     
      public static void main(String args[]){
            try{
                  String arr[] = new String[10];
                  arr = null;
                  arr[0] = "one";
                  System.out.print(arr[0]);
            }catch(Exception ex){
                  System.out.print("exception");
            }catch(NullPointerException nex){
                  System.out.print("null pointer exception");
            }   
      }
}

Answer & Solution
Correct Answer: Option D
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Vikyath Srinivasulu
Vikyath Srinivasulu 4 years ago
More specified exceptions need to be caught first. Here the general exception is caught first so it will give a compilation error.