Hello everyone,
I need to know which class multidimensional arrays in Java extends exactly?
When we assign
Object[] ref=new int[]{1,2,3};
the compiler complains that the objects are of different types. So it seems that one dimensional arrays extend Object
; I know that already.
But when we assign
Object[] ref2=new int[][]{{1,2,3},{4,5,6}};
the compiler will not complain. So it seems that two dimensional arrays extend Object[]
.
But when I print its superclass name:
System.out.println(ref2.getClass().getSuperclass().getName());
I got java.lang.Object
.
So can anyone explain what's going on here?