Page 1 of 1

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

Posted: Thu Aug 09, 2012 2:27 am
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.

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

Posted: Thu Aug 09, 2012 2:40 am
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 :)

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

Posted: Tue Aug 14, 2012 7:46 pm
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!)

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

Posted: Mon Aug 20, 2012 10:09 am
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

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

Posted: Mon Aug 20, 2012 11:01 am
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.

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

Posted: Tue May 27, 2014 4:16 pm
by JeramieH
Ugh, I missed this one because I thought about the "local variables aren't initialized" part... but this was helpful.

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

Posted: Fri Mar 03, 2017 4:06 pm
by AndaRO
So, local variables of type array are initialized.
Local primitive variables aren't initialized.

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

Posted: Fri Mar 03, 2017 9:54 pm
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.