Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q on Threads.

 
vadiraj vd
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
This question is from Mughal's mock exam. Could anyone give me an answer with explaination ?
Thanks,
CODE
---------
<pre>

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();
}
}

</pre>
--------
END OF CODE

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
 
nan sh
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.javaranch.com/ubb/Forum24/HTML/007044.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic