Multiple choice technology programming languages

2) What will be the output of the following program when it is made to run with the options "java scjp5_0.chap07.Ques01 1"package scjp5_0.chap07;public class Ques01 { public static void main(String[] args) { for (int i = 0; i < 2; i ++){ try{ System.out.println(args[i]); }catch(Exception e){} } }}

  1. The program will output 'scjp5_0.chap07.Ques01 1'.

  2. The program will output 1.

  3. The program will output '1' and then will raise an ArrayIndexOutOfBoundsException.

  4. The program won't print anything but will raise an ArrayIndexOutOfBoundsException at run-time.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The program is run with one command-line argument: "1". args[0] is "1", args[1] does not exist. First iteration (i=0) prints args[0] which is "1". Second iteration (i=1) tries to print args[1], which throws ArrayIndexOutOfBoundsException. The catch block silently ignores it. The loop ends. Only "1" is printed. Option C is wrong because the exception is caught.