Array is defined as int[ ] x = new int[5]; then x.length will give value 5, what is length? method / data member and if so then of which class (surely it will not method) regards, sujit
Shrini Kulkarni
Ranch Hand
Joined: Jan 12, 2001
Posts: 63
posted
0
For Arrays - "length" is data members which will specify the number of elements in the Array.
"length" can not be a method as it does not use () while being called.
Sun Certified programmer for Java2 platform.<BR>Shri_mk@hotmail.com
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
posted
0
All arrays are an object of the Array class. length is a data member of that class. It can be a data mamber because this information is set. Try this
int [] x = new int[5]; x.getClass().getName() gives [I if(x instanceof Array) --> this gives error Class Array Not Found I have checked, class Array is in java.lang.reflect package what is class for array object and what is length ?
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
posted
0
Eventhough arrays are objects, they are instantiated without the class name, which means they don't belong to any class as such. Since arrays are objects, x instanceof Object returns true. The java.lang.reflect.Array class provides static methods to dynamically create and access Java arrays. It is for a different purpose. Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Sujit Kurtadikar
Ranch Hand
Joined: Dec 05, 2000
Posts: 68
posted
0
Dear Ajith, if x is array, then (x instanceof Object) gives result true. Now it is clear to me. Still I have doubt about .length ? length is member of which class ? It has to be memeber of some class. x.getClass().getName() gives result [I , what is meaning of [I sujit [This message has been edited by Sujit Kurtadikar (edited January 17, 2001).] [This message has been edited by Sujit Kurtadikar (edited January 17, 2001).]