Not a waste at all. I tried the codes you posted and I believe you need a tr/catch block at the 5 seconds. So the answer is compilation error.
I tried the original question on Marcus exam 1 and not getting what's been suggested. Not sure if its has anything to do with different OS. Tried the same codes on w2K and Linux and getting the same answer.
With the original Marcus codes I got a single "Van" without the thread.sleep. Can you advise on this?
Thanks in advanced, k [ September 18, 2004: Message edited by: Kay Liew ]
Unity can only be manifested by the Binary. Unity itself and the idea of Unity are already two.
Joined: May 24, 2003
The result I got too is "Van%". And that's perfectly valid answer. The answer can be anything between "Vandeuler" to "Vandeuler 0 1 2 3 ".
the piggy method manipulates local parameter sname and not the class variables. So the concatenation operation doesn't have any effect on member sname.
Second when the JVM executes the start() statement, it churn out new child Thread. Now there are two possibility. The new thread can be schedule to execute immediately (thus making the parent thread wait) or continue with execution of parent method (piggy). Thus we get the answer.
Java specification maintains that the order of thread executions is undetermined.
This is a "stinker" of a question, possible more tricky than you will get on the real exam. However, it is very important to know that some thread behaviour is undetermined in Java. Thus whatever happens 100 times on your particular operating system and setup does not guarantee that the same behaviour will happen on some other operating system and setup.