The members of an array type (§10.7) are all of the following:
Object
(§4.3.2, §20.1)
length
, which is a constant (final
) field of every array; its type is int
and it contains the number of components of the array
class Test { public static void main(String[] args) { int[] ia = new int[3]; int[] ib = new int[6]; System.out.println(ia.getClass() == ib.getClass()); System.out.println("ia has length=" + ia.length); } }
true ia has length=3
This example uses the method getClass
inherited from class Object
and the
field length
. The result of the comparison of the Class
objects in the second
println
demonstrates that all arrays whose components are of type int
are
instances of the same array type, which is int[]
.