About Question enthuware.ocajp.i.v7.2.843 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
iamslrr
Posts: 6
Joined: Sun Dec 20, 2015 1:23 pm
Contact:

About Question enthuware.ocajp.i.v7.2.843 :

Post 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.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.843 :

Post 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.
If you like our products and services, please help us by posting your review here.

iamslrr
Posts: 6
Joined: Sun Dec 20, 2015 1:23 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.843 :

Post by iamslrr »

I was curious about the [I and [[I.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.843 :

Post by admin »

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.

vlezz94
Posts: 12
Joined: Wed Sep 28, 2016 6:31 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.843 :

Post 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?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.843 :

Post by admin »

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.

vlezz94
Posts: 12
Joined: Wed Sep 28, 2016 6:31 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.843 :

Post by vlezz94 »

Thanks Paul, don't know how I missed the [L

Post Reply

Who is online

Users browsing this forum: No registered users and 61 guests