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
NickWoodward
Posts: 29
Joined: Mon Mar 30, 2015 6:00 pm
Contact:

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

Post by NickWoodward »

int[][][] arr3 = {arr2};

so the brackets surrounding arr2 represent the third dimension of the array, and arr2 is a 2d element inside that dimension?

that is an evil question :D

Nick

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

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

Post by admin »

That is correct.
If you like our products and services, please help us by posting your review here.

Kevin30
Posts: 28
Joined: Sun Oct 25, 2015 10:14 am
Contact:

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

Post by Kevin30 »

To simplify the principle, the following is a valid 2-dimensional array:

int[][] array2D = {{1,2}};

But what does it look like?
In trying out the code, I've figured out that:
array2D[0][0] = 1
array2D[0][1] = 2

But what about array2D[1]?
Is it null? It doesn't look like it. When I try to print it, I get a ArrayIndexoutofBoundsExeption.

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

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

Post by admin »

You get a ArrayIndexoutofBoundsExeption upon accessing array2D[1] because the length of array2D is 1. It has only one element, which is accessed through array2D[0].

array2D[0] points to an array of 2 elements i.e. { 1, 2 }. That is why when you do array2D[0][0], you get 1, and when you do array2D[0][1], you get 2.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 »

The second answer, the correct answer is like this: int [] [] [] array3D = { { {0, 1}, {2, 3}, {4, 5} } };

Is this visual representation correct?
Image

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

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

Post by admin »

Yes, your visual representation is correct.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 97 guests