Java OCA OCP Practice Question 1798

Question

Given the following program, which statements are true?.

public class Main {
  public static void main(String[] args) {
    try {//from   w w  w  . ja  v a 2  s  .  c om
      if (args.length == 0) return;
      System.out.println(args[0]);
    } finally {
      System.out.println("The end");
    }
  }
 }

Select the two correct answers.

  • (a) If run with no arguments, the program will produce no output.
  • (b) If run with no arguments, the program will print "The end".
  • (c) The program will throw an ArrayIndexOutOfBoundsException.
  • (d) If run with one argument, the program will simply print the given argument.
  • (e) If run with one argument, the program will print the given argument followed by "The end".


(b) and (e)

Note

If run with no arguments, the program will print "The end".

If run with one argument, the program will print the given argument followed by "The end".

The finally block will always be executed, no matter how control leaves the try block.




PreviousNext

Related