nerdexam
Oracle

1Z0-851 · Question #48

Given: public class Foo { static int[] a; static { a[0]=2; } public static void main( String[] args ) {} } Which exception or error will be thrown when a programmer attempts to run this code?

The correct answer is C. java.lang.ExceptionInInitializerError. See the full explanation below for the reasoning.

Question

Given: public class Foo { static int[] a; static { a[0]=2; } public static void main( String[] args ) {} } Which exception or error will be thrown when a programmer attempts to run this code?

Options

  • Ajava.lang.StackOverflowError
  • Bjava.lang.IllegalStateException
  • Cjava.lang.ExceptionInInitializerError
  • Djava.lang.ArrayIndexOutOfBoundsException

How the community answered

(33 responses)
  • A
    6% (2)
  • B
    3% (1)
  • C
    82% (27)
  • D
    9% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice