jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question" Watch "Thread Question" New topic

Thread Question

Jo Liang

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; )
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...
I agree. Here's the link: http://aspose.com/file-tools
subject: Thread Question
It's not a secret anymore!