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.