This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question" Watch "Thread Question" New topic
Author

Thread Question

Jo Liang
Greenhorn

Joined: Dec 10, 2001
Posts: 11
1.public class SyncTest {
2.private int x;
3.private int y;
4.public synchronized void setX (int i) ( x=1; )
5.public synchronized void setY (int i) ( y=1; )
6.public synchronized void setXY(int 1)( set X(i); setY(i); )
7.public synchronized Boolean check() ( return x !=y; )
8.)
Under which conditions will check () return true when called from a different class?
A.check() can never return true
B.check() can return true when setXY is called by multiple threads
C.check() can return true when multiple threads call setX and setY separately.
D.Check() can only return true if SyncTest is changed to allow x and y to be set separately.

The given answer is B. But I am not sure that's the right answer. And I don't know what is the point of this question. What does it try to test?
Thank you in advance.

(Marilyn disabled smilies)
[ May 05, 2002: Message edited by: Marilyn deQueiroz ]
Uma Viswanathan
Ranch Hand

Joined: Jun 14, 2001
Posts: 126
Answers are B and C.
Give a search to get good explanations. The same question had been discussed earlier in this forum...
 
 
subject: Thread Question
 
Similar Threads
Question on synchronisation
Qn on Threads
confuse on the answer
Question on threads
Thread question . Please help .