This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Under which conditions will check() return when called from a different class. Choose one
A. check() can never return true B. check() can return true when set XY is called by multiple threads C. check() can true when multiple threads call set X and set Y separately D. check() can only return true if synchTest is changed to allow x and y to be set separately [ January 25, 2003: Message edited by: Jessica Sant ]
A) isnt right, because of B) Answer B) is right. A call to setXY makes calls to the synchronized methods setX / setY. But the method setXY isn't synchronized. So it can be called by multible threads. Ex: When thread1 call setXY(8), method setX(8) called. Here comes thread2 with call setXY(9). Thread1 leaves setX(8) and call setY(8). Now Thread2 can enter setX(9) Thread1 call check() and ups! x==9, y==8! C) Can't happen, cause setX/setY are private D) completely beside it
brian, Welcome to Javaranch, a friendly place for Java greenhorns We ain't got many rules 'round these parts, but we do got one. Please change your displayed name to comply with the JavaRanch Naming Policy. Thanks Pardner! Hope to see you 'round the Ranch!