Q63
Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a, b and c at any time?
class Counter {
int v = 0;
synchronized void inc() { v++; }
synchronized void dec() { v--; }
}
public class Q7ed5 {
Counter i;
Counter j;
Counter k;
public synchronized void a() {
i.inc();
System.out.println("a");
i.dec();
}
public synchronized void b() {
i.inc(); j.inc(); k.inc();
System.out.println("b");
i.dec(); j.dec(); k.dec();
}
public void c() {
k.inc();
System.out.println("c");
k.dec();
}
}
1) i.v is guaranteed always to be 0 or 1.
2) j.v is guaranteed always to be 0 or 1.
3) k.v is guaranteed always to be 0 or 1
4) j.v will always be greater than or equal to k.v at any give time.
5) k.v will always be greater than or equal to j.v at any give time.
Q64
Which statements concerning casting and conversion are true?
1) Conversion from int to long does not need a cast.
2) Conversion from byte to short does not need a cast.
3) Conversion from float to long does not need a cast.
4) Conversion from short to char does not need a cast.
5) Conversion from boolean to int using a cast is not possible.
Q65
Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?
public class Qdd1f {
public long sum(long a, long b) { return a + b; }
// insert new method declaration here
}
1) public int sum(int a, int b) { return a + b; }
2) public int sum(long a, long b) { return 0; }
3) abstract int sum();
4) private long sum(long a, long b) { return a + b; }
5) public long sum(long a, int b) { return a + b; }
Q66
The 8859-1 character code for the uppercase letter A is 65. Which of these code fragments declare and initialize a variable of type char with this value?
1) char ch = 65;
2) char ch = '/65';
3) char ch = '/0041';
4) char ch = 'A';
5)char ch = "A";
1) 4
2) 2
3) 2
4) 2, 6
5) 4
6) 3
7) 4
8) 4
9) 1, 2, 3, 5
10) 1, 5
11) 4
12) 5
13) 1
14) "LayoutManager layout = new GridLayout(2, 3);"
or: "LayoutManager layout = new GridLayout(2, 3)"
15) 5
16) 3
17) 2, 4
18) 4, 5
19) 2
20) 4
21) 4
22) 5
23) 1, 2
24) 2
25) 1, 4
26) 3
27) 4
28) 3 (? no run-time exception)
29) 1, 4, 5
30) 5
31) 2, 5
32) 1
33) 3, 4
34) 2, 3
35) 2, 4
36) 3, 5
37) 2, 5
38) 3, 4
39) 1
40) 1, 2, 3
41) "wait"
42) 3
43) 3
44) 5
45) 4
46) 1, 2, 3, 4
47) 2
48) 1, 2, 4
49) 1
50) 2, 3
51) 1, 5
52) 1, 3
53) 1
54) 2, 5
55) 5
56) 2, 3
57) 4
58) 2, 3
59) 5
60) super.print();
61) 4
62) 1
63) 1,2
64) 1,2,5
65) 1,5
66) 1,4