Java OCA OCP Practice Question 952

Question

What is the result of running the following program?

1:   package fun; 
2:   public class MyClass { 
3:      static int[][] game; 
4: //from w ww . ja v a2s.  c  o  m
5:      public static void main(String[] args) { 
6:         game[3][3] = 6; 
7:         Object[] obj = game; 
8:         game[3][3] = "X"; 
9:         System.out.println(game[3][3]); 
10:     } 
11:  } 
  • A. X
  • B. The code does not compile.
  • C. The code compiles but throws a NullPointerException at runtime.
  • D. The code compiles but throws a different exception at runtime.


B.

Note

Line 8 attempts to store a String in an array meant for an int.

Line 8 does not compile, and Option B is correct.




PreviousNext

Related