A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Node.js in Action
this week in the
Joined: Sep 27, 2005
Sep 29, 2005 03:53:00
What is the output of this prg?
public class MyThread implements Runnable
myString = "Yes ";
public void run()
this.myString = "No ";
public static void main(String args)
MyThread t = new MyThread();
for (int i=0; i < 10; i++)
When I run this program ,it gives yes 9times,but in one of the mock exam it gives the answer "the ouput cannot be determined."
Am i correct?
Joined: Sep 28, 2005
Sep 29, 2005 04:21:00
You're right... (If you ave one "No" after your 9 "Yes", or ten "Yes")
Try to add loops (ex: i<1000)
You'll probably see "No" printed some times...
It will make more clear the assertion "the output cannot be determined".
In fact, the output can be defined by :
- A sequence of 10 words wille be printed : An indetermined number of "Yes" followed by zero or more "No".
Regards,<br />Seb<br /> <br />SCJP 1.4
Joined: May 22, 2003
Sep 29, 2005 05:54:00
General rule: Don't depend on the thread scheduler for behavior.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
a question about thread.
Aaargh! Still Weak on Threads
java.lang package is not importing by default
THREAD QUESTION OF K&B!! confused
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014