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
There is no single answer to this question. Anyone can include a length
variable in a class, but there's no guarantee that it exists -- or, if it does exist, that it's public -- in any given class. You really just have to read the source for the class you're interested in.
I will say that in the widely-used JavaBean convention, classes that could reasonably have a length attribute but don't have a public variable length
often have getLength()
and setLength()
methods. That's better than a public variable for a number of reasons that are kind of out of scope for your question, but if you're interested, check out this related SO question.