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)- A6% (2)
- B3% (1)
- C82% (27)
- D9% (3)
Community Discussion
No community discussion yet for this question.