This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
the answer is output cannot be determined as expected but since the strings are never changed the output would be Me You Me You Me You Me You woudn't it ...given the threads do run..since the order will not matter ..do we take for granted that when we start two threads the output can never be determined even if it is said that no other thread runs at that time (though this particular question does not say that)?
Hi Soum: I would agree with your analysis that output is deterministic because both threads are printing identifical strings twice. Therefore, which string is printing which line is immaterial. Have you tried to contact the source of this question about their willingness to re-evaluate this question? Thanks Barkat [ September 04, 2002: Message edited by: Barkat Mardhani ]
Joined: May 31, 2002
well i don't have time to get back to them..i go for the exam tomorrow....so for the exam i would go for the 'indeterminate' option if they specifically don't mention anything about any other threads running or not running.
Joined: Aug 05, 2002
Hi Soum: That is seem good strategy. Good luck on your exam.
Because Strings are immutable. The concat method returns a new String, which we would need to capture with: String foo = "foo"; System.out.println(foo); foo.concat("bar"); System.out.println(foo); Would return: foo foo Whilst: String foo = "foo"; System.out.println(foo); bar = foo.concat("bar"); System.out.println(bar); Would return: foo foobar Cheers, Neil