This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question" Watch "Thread Question" New topic
Author

Thread Question

Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183

Given the foll Question -



The options are (Choose 1): -

A) Prints "ready to print , now printing" without any exception
B) Prints "ready to print , now printing,printed" without any exception
c) Run time Exception
d) Compiler error

Answer is a).

Should not it be unpredictable bec' result can be either : -

Prints "ready to print , now printing" without any exception OR
Prints "now printing ,ready to print " without any exception


pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Simran Dass wrote:
Given the foll Question -




There are too many typos and errors present to tell just what this will do. Even if I fix them to get this to compile, the run method is never called as start is not called on any thread.


Edit:
Except, if you do happen to call start on t immediately after it was created, then you'll see your results.

Question: what object is domore synchronized to? What object gets the called with notifyAll()?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

pete stein wrote:
Simran Dass wrote:
Given the foll Question -




There are too many typos and errors present to tell just what this will do. Even if I fix them to get this to compile, the run method is never called as start is not called on any thread.


Edit:
Except, if you do happen to call start on t immediately after it was created, then you'll see your results.

Question: what object is domore synchronized to? What object gets the called with notifyAll()?


I think, your question should be like this.




Output :
Now printing
Ready to print


And waiting for a notification, since this will not be notified in future, We have to forcefully exit the code.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Question
 
Similar Threads
Thread question doubt
wait() not syncronized on this but not throwing illegalMonitorStateException
Thread
Thread Question from Examlab
Thread question