1. Home
  2. Computing & Technology
  3. Computer Certification

Question 24

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);

                        }

            }

 

Compilation Error
Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.
Prints : No No No No No No No No No No and so on.
Prints : Yes No Yes No Yes No Yes No Yes No and so on.
The Output cannot be determined.

Back to beginning | Next Question



Explore Computer Certification
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Computer Certification

©2009 About.com, a part of The New York Times Company.

All rights reserved.