Multiple choice technology programming languages

What will be the output on compiling/running the following code? public class MyThread implements Runnable { String myString = "Yes "; public void run() { this.myString = "No "; } public static void main(String[] args) { MyThread t = new MyThread(); new Thread(t).start(); for (int i=0; i < 10; i++) System.out.print(t.myString); } }

  1. Compilation Error

  2. Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.

  3. Prints : No No No No No No No No No No and so on.

  4. Prints : Yes No Yes No Yes No Yes No Yes No and so on.

  5. The Output cannot be determined.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Because a new thread is spawned to modify the shared variable without synchronization, there is a race condition between the main loop printing the variable and the child thread writing to it. The output depends on JVM thread scheduling and is therefore unpredictable.