A

Admin • 825.56K Points
Coach

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

  • (A) "one" is printed.
  • (B) "exception" is printed.
  • (C) "null pointer exception" is printed.
  • (D) "null pointer exception" is printed. D. Compilation fails saying NullPointerException has already been caught.
  • Correct Answer - Option(D)
  • Views: 10
  • Filed under category Java
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.