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?
<pre>
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();
}
}
</pre> select valid answer
1. i.v is guranteed to be always 0 or 1
2. j.v is guranteed to be always 0 or 1
3. k.v is guranteed to be always 0 or 1
4. j.v will be greater than or equal to k.v at all times
5. k.v will be greater than or equal to j.v at all times
Beats me. Any ideas anyone ?
rgds
Sahir