1Z0-803 · Question #59
Given the code fragment: Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}}; Systemout.printIn(array [4] [1]); System.out.printIn (array) [1][4]); int [] [] array = {{0}, {0,
The correct answer is D. 4 An ArrayIndexOutOfBoundException is thrown at run time. The first println statement, System.out.println(array [4][1]);, works fine. It selects the element/array with index 4, {0, 4, 8, 12, 16}, and from this array it selects the element with index The second println statement, System.out.println(array) [1][4]);, fails. It selects the
Question
Given the code fragment:
Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}}; Systemout.printIn(array [4] [1]); System.out.printIn (array) [1][4]); int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}}; System.out.println(array [4][1]); System.out.println(array) [1][4]); What is the result?
Options
- A4 Null
- BNull 4
- CAn IllegalArgumentException is thrown at run time
- D4 An ArrayIndexOutOfBoundException is thrown at run time
How the community answered
(29 responses)- A3% (1)
- B17% (5)
- C10% (3)
- D69% (20)
Explanation
The first println statement, System.out.println(array [4][1]);, works fine. It selects the element/array with index 4, {0, 4, 8, 12, 16}, and from this array it selects the element with index The second println statement, System.out.println(array) [1][4]);, fails. It selects the array/element with index 1, {0, 1}, and from this array it try to select the element with index 4. This causes an Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
Topics
Community Discussion
No community discussion yet for this question.