jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on thread q.2 pg 734 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on thread q.2 pg 734" Watch "Question on thread q.2 pg 734" New topic

Question on thread q.2 pg 734

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
public class Letters extends Thread {
private String name;
public Letters(String name) {
this.name = name;
public void write() {
public static void main(String[] args) {
new Letters("X").start();
new Letters("Y").start();
We want to guarantee that the output can be either XXYY or YYXX, but never XYXY or any other combination. Which of the following method definitions could be added to the Letters
class to make this guarantee? (Choose all that apply.)
A. public void run() { write(); }
B. public synchronized void run() { write(); }
C. public static synchronized void run() { write(); }
D. public void run() { synchronized(this) { write(); } }
E. public void run() { synchronized(Letters.class) { write(); } }
F. public void run() { synchronized(System.out) { write(); } }
G. public void run() { synchronized(System.out.class) { write(); } }

Ans -- E,F .
Can someone explain me.

Thanks<br />Dinesh
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Hi Dinesh -

I see that you're asking a lot of questions from the threads chapter of our book. I think it would be better to start with one question, tell us what you think is going on, and we'll start a conversation from there. It could be that you might have to go back and reread some parts of the chapter, but we can't really tell until you give us more info about what parts make sense to you and what parts are confusing.

Thanks, I'm going to shut down the other threads.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486

Not only , there are many people who have on therads.
As therad is considered as of the imp topics and many questions are asked in exams, to clear my doubt that is why i am posting questions so that i can get clear picture .

jQuery in Action, 3rd edition
subject: Question on thread q.2 pg 734
It's not a secret anymore!