i got this question from one of the mock tests. And says only 2 & 3 will compile.
import java.util.*;
class DumpArray {
public static void main(String [] args) {
int [] a = {7,9,8};
int [][] aa = {{1,2,3}, {6,5,4}};
int [][][] aaa = {{{1,2}, {3,4}}, {{5,6},{7,8}}};
System.out.println(Arrays.deepToString(a)); // 1
System.out.println(Arrays.deepToString(aa)); // 2
System.out.println(Arrays.deepToString(aaa)); //3
}
}
But, according to me nothing should compile. Because, deepToString method takes Object[] as parameter. As arrays of primitive types are not sub types of Object[] but Object.
Even if a, aa,aaa are arrays of Integer class, 1 and 2 should compile. as the 3 dimension array is not properly initialized.
Please suggest.
Thanks