Question discussion

Predict the output:public class Test{ public static void main(String args[]){ try{ String arr[] = new String[10]; arr = null; arr[0] = "one…

312199Medium 1 reply 880 views
2
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.
  • DCompilation fails saying NullPointerException has already been caught.
  • ENone of these
Correct answer: D

Discussion 1

0
CCommunity
Compilation fails saying NullPointerException has already been caught.