This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes // thread question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "// thread question" Watch "// thread question" New topic
Author

// thread question

Meg Adal
Ranch Hand

Joined: Mar 12, 2002
Posts: 70
Question from Sun Guoqiao's SCJP2 Mock Exam No. 2 - New Version

The output is
0
0
1
Can anybody explain me why it is so?
Thanks in advance
Megan
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The main thread starts the thread t, and then waits
for t to finish (t.join()).
Thread t will do its thing by running the run() method, printing 0.
Thread t finishes and the main thread continues
after the t.join().
The main thread then calls t.run() producing the second 0, and then the main thread calls t.demo() producing the 1.
-Barry
[ August 28, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: // thread question
 
Similar Threads
Illustration about locking (Threads)
String constant pool and synchronization
Confused with mock exam question
Doubt in Threads Synchronization
[B]Class Monitor Vs. Object Monitor[/B]