Java OCA OCP Practice Question 1401

Question

Considering the following program, which of the options are true?

public class Main{ 
   public static void main (String args []){ 
      try{ /*from  w w  w.j  a  v a2 s  . co m*/
          if  (args.length == 0) return; 
          else throw new Exception ("Some Exception"); 
       } 
      catch (Exception e){ 
          System.out.println ("Exception in Main"); 
       } 
      finally{ 
          System.out.println ("The end"); 
       } 
    } 
} 

Select 2 options

  • A. If run with no arguments, the program will only print 'The end'.
  • B. If run with one argument, the program will only print 'The end'.
  • C. If run with one argument, the program will print 'Exception in Main' and 'The end'.
  • D. If run with one argument, the program will only print 'Exception in Main'.
  • E. Only one of the above is correct.


Correct Options are  : A C

Note

Even if the program is executed without any arguments, the 'args' is NOT NULL.

In such case it will be initialized to an array of Strings containing zero elements.

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

Only if, in a try or catch block, System.exit() is called then finally will not be executed.




PreviousNext

Related