Java OCA OCP Practice Question 800

Question

What will the following class print ?

public class Main {
   public static void main(String[] args) {
      int[][] a = { { 00, 01 }, { 10, 11 } };
      int i = 99;
      try {/* ww  w.j  a v  a2  s.  c  om*/
         a[getIndex()][i = 1]++;
      } catch (Exception e) {
         System.out.println(i + ", " + a[1][1]);
      }
   }

   static int getIndex() throws Exception {
      throw new Exception("unimplemented");
   }
}

Select 1 option

  • A. 99 , 11
  • B. 1 , 11
  • C. 1 and an unknown value.
  • D. 99 and an unknown value.
  • E. It will throw an exception at Run time.


Correct Option is  : A

Note

While evaluating a[val()][i= 1]++, when val() throws an exception, i= 1 will not be executed.

i remains 99 and a[1][1] will print 11.




PreviousNext

Related