FaisalAhmed FaisalAhmed - 3 months ago 20
Java Question

length field in Object Class

Sorry if this question have been asked before. I have some doubts regarding length field of Object class. Correct me if i am wrong, Every class impilcitly extends Object class thats why we can access every methods like equals,clone,hashcode etc

So my question is when we create any array for example array of int[] ,foo[] we can access length field of Object class but when we create any object we can not see length variable, why?

Answer

The Object class does not define a length field, and an Object does not have one.

The length field is defined for arrays types only. It is a declared implicitly.

... when we create any object we can not see length variable, why?

Why? Because it doesn't have one!