In which class is the length field defined in Java (e.g. for array length)?
Will I be able to see it defined say in Object class?
EDIT : Wh
Any class can have a field called length. Just add it.
Arrays do not have a length field; they have something which looks like such a field:
int[] a = new int[10];
System.out.println("array length is: " + a.length);
but it is not really a plain field, because this does not compile:
int[] a = new int[10];
a.length = 42; // <- here the compiler gets grumpy
and, at the JVM level, the array length is accessed with a specific opcode (arraylength) and not the generic instance field access opcode (getfield).