The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 13:

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); 
    } 
}
A. Compilation Error
B. Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.
C. Prints : No No No No No No No No No No and so on.
D. Prints : Yes No Yes No Yes No Yes No Yes No and so on.
E. The Output cannot be determined.