MCQ Single Best Answer Not Set

QPredict 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");
            }   
      }
}

ID: #2336 Java Exception MCQ 597 views
Question Info
#2336Q ID
Not SetDifficulty
Java Exception MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A "one" is printed.
  • B "exception" is printed.
  • C "null pointer exception" is printed.
  • D Compilation fails saying NullPointerException has already been caught.
Correct Answer: Option D

Explanation

Compilation fails saying NullPointerException has already been caught.

Share This Question

Challenge a friend or share with your study group.