I. synchronized void chat(long id) {
II. void chat(long id) {
The explanation to this ques's answer in the book says:
F is correct. With fragment I, the chat method is synchronized, so the two threads can't
swap back and forth.
With either fragment, the first output must be yo.
but when i ran this code on my system the output" dude dude yo yo "also was displayed a few times
and acc. to me this output is totally justified.....(eplanation is as follows )
as the first
thread could start running(sets flag=id in the if condition) and then before it starts executing the for loop the other thread starts and executes completely.
Thus would lead to the output as quoted above.
Am i right guys??....please confirm this reasoning(by me)....!!!