Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 166

Given:

and the code fragment:

The threads t1 and t2 execute asynchronously and possibly prints ABCA or AACB.

You have been asked to modify the code to make the threads execute synchronously and prints ABC.

Which modification meets the requirement?

    Correct Answer: C

    To ensure that the threads execute synchronously and print 'ABC', the run() method needs to be synchronized. This ensures that one thread completes its execution of the run() method before the other thread can execute it. Replacing line n2 with 'public synchronized void run () {' will achieve this.

Discussion
JME_CHGOption: C

C is correct, A does nothing...

WilsonKKerllOption: C

I think C is answer.

steefaandOption: C

C is answer.

iSnoverOption: C

The answer is letter C, answer A does not print anything on the screen and the run() method needs to be syncronized.

WilsonKKerll

public void run() { while(count < src.length){ System.out.println(src[count++]); } }