About Question enthuware.ocajp.i.v7. 2 .1380 :

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

Moderator: admin

Post Reply
subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

About Question enthuware.ocajp.i.v7. 2 .1380 :

Post by subhamsdalmia »

Dont understand the difference between,
{{0, 1}, {2, 3}, {4, 5}};
and
{ { {0, 1}, {2, 3}, {4, 5} } };

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

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

Post by admin »

To start with, did you notice the difference in number of opening and closing brackets?
If you like our products and services, please help us by posting your review here.

subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

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

Post by subhamsdalmia »

Yes, syntactically, they are different.
So, does that mean to separate dimensions in arrays, we require {}?

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

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

Post by admin »

Yes, try this - http://stackoverflow.com/questions/1067 ... ay-in-java

BTW, your question is too basic. You should first read a book to learn the basics and then attempt the mock exams. Otherwise, it will not help you much.
If you like our products and services, please help us by posting your review here.

subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

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

Post by subhamsdalmia »

kindly explain "int[][] arr2 = {arr, {1, 2}, arr};"
how is this valid?

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

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

Post by admin »

Again, it is quite basic. You need to go through a book and read a chapter on arrays.
It is not really possible to explain the whole chapter in a post here. Briefly, arr2 is a two dimensional array of ints, so each element of arr2 must be a one dimensional array of ints, which is what {arr, {1, 2}, arr} is doing.
If you like our products and services, please help us by posting your review here.

subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

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

Post by subhamsdalmia »

Understood.
Its array of array we are looking at.
We say its 2D array, and elements are 1D.
"," separates each element.
So, the above mentioned elements form only one part of aoa.
But, {1,2}, whats that?
AND
hows {arr, {1, 2}, arr} different from {{0, 1}, {2, 3}, {4, 5}}

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

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

Post by admin »

Please go through the link I gave you above. Read all the answers there.
If you like our products and services, please help us by posting your review here.

subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

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

Post by subhamsdalmia »

Have gone thru the link multiple times but haven't been able to understand hows {arr, {1, 2}, arr} different from {{0, 1}, {2, 3}, {4, 5}}!

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

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

Post by admin »

What kind of difference are you looking for?
In the initialization part of arr2, each element of arr2 has to be either a reference to a one dimensional array of ints or a definition of another one dimensional array itself. arr is a reference to a 1 dimensional array and {0, 1} is just another one dimensional array. So what is the problem?
If you like our products and services, please help us by posting your review here.

subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

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

Post by subhamsdalmia »

Then why is {{0, 1}, {2, 3}, {4, 5}} invalid
and {arr, {1, 2}, arr} valid?

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

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

Post by admin »

You need to read the explanation. It explains exactly the question that you are asking.
{{0, 1}, {2, 3}, {4, 5}} can't be assigned to array3D because {{0, 1}, {2, 3}, {4, 5}} is only a two dim array.

The statement int[][] arr2 = {arr, {1, 2}, arr}; is valid because {arr, {1, 2}, arr} is a two dim array and arr2 is variable of type 2d array of ints.
If you like our products and services, please help us by posting your review here.

subhamsdalmia
Posts: 32
Joined: Sat May 02, 2015 11:57 pm
Contact:

Re: About Question enthuware.ocajp.i.v7. 2 .1380 :

Post by subhamsdalmia »

Thanks and sorry to bother.
Now, I understand more.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 65 guests