Oracle
1Z0-851 · Question #222
Given: 11. public static void main(String[] args) { 12. Object obj = new int[] { 1, 2, 3 }; 13. int[] someArray = (int[])obj; 14. for (int i : someArray) System.out.print(i + " "); 15. } What is the…
The correct answer is A. 1 2 3. See the full explanation below for the reasoning.
Question
Given: 11. public static void main(String[] args) { 12. Object obj = new int[] { 1, 2, 3 }; 13. int[] someArray = (int[])obj; 14. for (int i : someArray) System.out.print(i + " "); 15. } What is the result?
Options
- A1 2 3
- BCompilation fails because of an error in line 12.
- CCompilation fails because of an error in line 13.
- DCompilation fails because of an error in line 14.
- EA ClassCastException is thrown at runtime.
How the community answered
(40 responses)- A78% (31)
- B5% (2)
- C3% (1)
- D5% (2)
- E10% (4)
Community Discussion
No community discussion yet for this question.