About Question enthuware.ocajp.i.v7.2.843 :
Moderator: admin
-
- Posts: 6
- Joined: Sun Dec 20, 2015 1:23 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.843 :
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.
"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.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.843 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Sun Dec 20, 2015 1:23 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.843 :
I was curious about the [I and [[I.
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.843 :
Yes, such are the names for array classes. This is given in JLS but not important for the exam.
If you like our products and services, please help us by posting your review here.
-
- Posts: 12
- Joined: Wed Sep 28, 2016 6:31 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.843 :
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
So, if the class of the object is String (In this case), why when we add the isArray method returns true?
Now, the thing is that I removed the isArray method from the declaration
Resulting in:System.out.println(twoD[2].getClass().isArray());
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?
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.843 :
Look closely at the output. The class of the array is not String. It is [Ljava.lang.String.
If you like our products and services, please help us by posting your review here.
-
- Posts: 12
- Joined: Wed Sep 28, 2016 6:31 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.843 :
Thanks Paul, don't know how I missed the [L
Who is online
Users browsing this forum: No registered users and 61 guests