Multiple choice

What will be the output of the following code? import java.lang.*; public class One { public static void main(String arg[]) { int i[]={0,1,2,3,4,5}; Object o=i; int i2[]=(int[])o; for(int i3:i2) { System.out.print(i3); } } }

  1. 012345

  2. Compile time error

  3. Code will not produce output

  4. It will show error in Object o=i; and in for(int i3:i2)

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

This code demonstrates array type covariance and casting. An int array can be assigned to an Object reference, then cast back to int array. The for-each loop prints 012345. No errors occur.