Java OCA OCP Practice Question 1345

Question

What is the output of the following application?

package mypkg; /* w ww  . j  a  va  2 s  . co  m*/
public class Main { 
   public static void main(String... teams) { 
      try { 
         int score = 1; 
         System.out.print(score++); 
      } catch (Throwable t) { 
         System.out.print(score++); 
      } finally { 
         System.out.print(score++); 
      } 
      System.out.print(score++); 
   } 
} 
  • A. 123
  • B. 124
  • C. 12
  • D. None of the above


D.

Note

The application does not compile because score is defined only within the try block.

The correct answer is Option D.




PreviousNext

Related