This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question" Watch "Thread Question" New topic

Thread Question


Joined: Dec 01, 2000
Posts: 9
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() {;
public synchronized void b() {;;;
i.dec(); j.dec(); k.dec();
public void c() {;
Select all valid answers
1. i.v is guaranteed always to be or 1.
2. j.v is guaranteed always to be or 1.
3. k.v is guaranteed always to be or 1.
4. j.v will always be greater than or equal to k.v at any given time.
5. k.v will always be greater than or equal to j.v at any given time.
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Actually none of the answers are right. I started writing my explanation, but soon found out this exact topic has been discussed here before -

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link:
subject: Thread Question
It's not a secret anymore!