Multiple choice technology programming languages

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?

  1. 1 2 3

  2. B. Compilation fails because of an error in line 12.

  3. B. Compilation fails because of an error in line 13.

  4. B. Compilation fails because of an error in line 14.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

An int array is assigned to an Object reference (valid upcast). The Object is then cast back to int[](valid downcast since the runtime type is int[]). The enhanced for loop iterates over the array, printing 1 2 3. The cast succeeds because the actual object type is int[].