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

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

Moderator: admin

Post Reply
dtchky
Posts: 19
Joined: Wed Aug 01, 2012 3:11 am
Contact:

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

Post by dtchky »

Just an FYI :-)

In the answer section the explanation contains a couple of items that don't form part of the question:
int[] iA = new int[10]; will contain 10 integers with a value of 0.
Object[] oA = new Object[10]; will contain 10 object references pointing to null.

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

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

Post by admin »

This is to present the complete picture. While reading about an array of booleans, a curious mind would like to know what about an array of ints or an array of Objects :)

dtchky
Posts: 19
Joined: Wed Aug 01, 2012 3:11 am
Contact:

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

Post by dtchky »

Cool, no probs, I thought it might have been because the question was modified at some point and the explanation was forgotten about, though you are correct :-) It is useful info. (You can never have too much of that!)

AnotherGuest

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

Post by AnotherGuest »

I thought that 'str' (being a String) is immutable? ie even if bA[0] was true, str would still be "111"...

Could you confirm just in case I get a question similar to this on the exam?

Cheers

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

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

Post by admin »

AnotherGuest wrote:I thought that 'str' (being a String) is immutable? ie even if bA[0] was true, str would still be "111"...

Could you confirm just in case I get a question similar to this on the exam?

Cheers
No, str is not immumable. The String object being pointed to by str is immutable. You can make str point to different String objects, you can't change the String objects themselves. So if bA[0] was true, str would then be changed to point to another String object. The String object it pointed to originally would still be the same. In other words, "111" will not become "222", but str will point to another String containing "222".

If you want to prevent a variable from changing (i.e. prevent str from pointing to any other String object), you can make it final.

HTH,
Paul.

JeramieH
Posts: 22
Joined: Wed Jan 08, 2014 11:24 am
Contact:

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

Post by JeramieH »

Ugh, I missed this one because I thought about the "local variables aren't initialized" part... but this was helpful.

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

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

Post by AndaRO »

So, local variables of type array are initialized.
Local primitive variables aren't initialized.

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

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

Post by admin »

AndaRO wrote:So, local variables of type array are initialized.
Local primitive variables aren't initialized.
Where did you read this? How did you reach this conclusion that local variables of type array are initialized? This is incorrect. Local variables of any kind are not initialized by default.

Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests