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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
kirankumar
Posts: 5
Joined: Tue Apr 05, 2016 10:25 am
Contact:

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

Post by kirankumar »

For this question, I don't see the correct answer, can you please explain me which one is correct option? why?

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

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

Post by admin »

I see that correct answer and explanation has been given. (Screen shot attached.) Could you please confirm that you don't see this?
test.png
test.png (27.43 KiB) Viewed 4020 times
If you like our products and services, please help us by posting your review here.

SeoaneR
Posts: 8
Joined: Tue Nov 07, 2017 8:23 am
Contact:

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

Post by SeoaneR »

re: char cA[][] = new char[3][];

I thought that both the column and row have to be initialized with their sizes otherwise a NullpointerException is thrown.
Im i right in assuming that the below code creates the rows and therefore does not throw the NullPointer.
for (int i=0; i<cA.length; i++) cA = new char[4];

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

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

Post by admin »

new Char[3][] create an array with three elements where each element is automatically initialized to null. Because the type of the elements is char[], which in a reference type and not a primitive type.

new char[4] creates a char array with 4 elements where value of each element is automatically set to 0 (because char is a numeric primitive).

Therefore, for(int i=0; i<cA.length; i++) cA = new char[4]; assigns a char array of length 4 to each of the elements of cA.

Now, which dimension you call rows and which columns is up to you. Java arrays don't have the concept of rows and columns.

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

tcroots19
Posts: 6
Joined: Tue Nov 19, 2019 2:01 pm
Contact:

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

Post by tcroots19 »

#5 in the answer says "creates a one dimensional array", but it doesn't actually do that right? this fails to compile, the right side is a one dimensional array...that tries to go into a two dimensional array...let alone that it's not char. Am I right?

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

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

Post by admin »

The explanation is in the context of the problem statement, which asks for a two-dimensional array of chars. Variable declaration of the options is char[][], which is correct but the instantiation part of Option 5 is { "1234", "1234", "1234" };. The explanation is about this part.It creates a one dimensional array and that too of Strings. The implied (unsaid) part is, that is why it cannot be assigned to cA, which requires a two dimensional array of chars.

I am updating the explanation to avoid this confusion.

thank you for your feedback!
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 28 guests