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 Q1
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) {
s2.append("A");
synchronized(s2) {
s2.append("B");
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread() {
public void run() {
synchronized(s2) {
s2.append("C");
synchronized(s1) {
s1.append("D");
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}
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
Q2:
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 ...