Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Hi all giving scjp 1.4 on this sat help needed

Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i am new to this forum , can any one tell me the solutions of this question , i found these on some mock test


package test2;
public class SyncTest{
public static void main(String[] args) {
final StringBuffer s1= new StringBuffer();
final StringBuffer s2= new StringBuffer();
new Thread () {
public void run() {
synchronized(s1) {
synchronized(s2) {
new Thread() {
public void run() {
synchronized(s2) {
synchronized(s1) {

Which two statements are true? (Choose Two)

A. The program prints �ABBCAD�
B. The program prints �CDDACB�
C. The program prints �ADCBADBC�
D. The output is a non-deterministic point because of a possible deadlock condition.
E. The output is dependent on the threading model of the system the program is
running on.

in my opinion the ans is D,E but in answer section of the mock it is given as A,B


1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX( int i ) { x = i; }
5. private synchronized void setY( int i ) { y = i; }
6. public void setXY( int i ) { setX(i); setY(i); }
7. public synchronized boolean check() { return x != y; }
8. }

Under which condition 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 return true only if SyncTest is changed to allow x and y to be set separately.

a) Errors are subclasses of RuntimeEceptions
b No Exceptions are subclasses1of1XrrorsA
c} NO Errorsshould becatched1and1handledA
d}Runtime Exceptions ca

ans : In my opinion the answer should be B but it is given as C in mock answers.

Also one thing i gave 3 mocks of marcus green but scored only 78%,71% and 75% ... i am little bit worried whether i will make good score or not .
i small suggestion i need will K&B book , marcus green is enough for getting good score or i have to go for more material ...

Thanks in advance ...
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

For a discussion of the first question, see this thread.
I'm doing laundry! Look how clean this tiny ad is:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic