OCA Java SE 8 Mock Exam Review - OCA Mock Question 32








Question

What is the output of the following code?

public class Main {
  public static void main(String args[]) {
    int[] arr1;
    int[] arr2 = new int[3];
    char[] arr3 = { 'a', 'b' };
    arr1 = arr2;
    arr1 = arr3;
    System.out.println(arr1[0] + ":" + arr1[1]);
  }
}

    a  0:0 
    b  a:b 
    c  0:b 
    d  a:0 
    e  Compilation error 




Answer



E

Note

Arrays of int and char primitives aren't the same as a primitive int or char.

Arrays themselves are reference variables.