Page 1 of 1
About Question enthuware.ocajp.i.v7.2.843 :
Posted: Tue Dec 22, 2015 5:17 pm
by iamslrr
I don't understand the statement:
"In Java, arrays are just like regular Objects and arrays of different types have different class names. For example, the class name of an int[] is [I and the class name for int[][] is [[I."
that is in the explaination of this question.
Re: About Question enthuware.ocajp.i.v7.2.843 :
Posted: Tue Dec 22, 2015 10:41 pm
by admin
Can you please tell me which part of the sentence do you not understand? It is just telling you that every array type is an object of some class. It then shows you the names of those classes as an example.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.843 :
Posted: Wed Dec 23, 2015 1:21 pm
by iamslrr
I was curious about the [I and [[I.
Re: About Question enthuware.ocajp.i.v7.2.843 :
Posted: Wed Dec 23, 2015 8:59 pm
by admin
Yes, such are the names for array classes. This is given in JLS but not important for the exam.
Re: About Question enthuware.ocajp.i.v7.2.843 :
Posted: Mon Dec 19, 2016 12:55 pm
by vlezz94
When I ran this code I tried to change the type of the array with Integer(Wrapper class), long and finally String (Added a bunch of null fields).
Now, the thing is that I removed the isArray method from the declaration
System.out.println(twoD[2].getClass().isArray());
Resulting in:
System.out.println(twoD[2].getClass());
//Output: class [Ljava.lang.String;
So, if the class of the object is String (In this case), why when we add the isArray method returns true?
Re: About Question enthuware.ocajp.i.v7.2.843 :
Posted: Mon Dec 19, 2016 1:08 pm
by admin
Look closely at the output. The class of the array is not String. It is [Ljava.lang.String.
Re: About Question enthuware.ocajp.i.v7.2.843 :
Posted: Mon Dec 19, 2016 1:28 pm
by vlezz94
Thanks Paul, don't know how I missed the [L