public class UseCounter3 {
	Counter c;                         
	public UseCounter3() {
		c = new Counter(0);
		for (int i = 0; i < 10; i++) {
		  new Thread(new Runnable() {
		    public void run() { callCounter(); }
		  }).start();
		}
	}

	private void callCounter() {
        int val = 0;
        try {
            Thread.sleep(20);
		    val = c.getAndIncrement(); 
        } catch (InterruptedException e) {}
		System.out.println("Value of counter = " + val);
	}
	
	public static void main(String[] args) {
		new UseCounter3();
	}
}

class Counter {
	private int value;

	public Counter(int c) {
		value = c;
	}

	public int getValue() {
		return value;
	}

	public int getAndIncrement() {
		int temp = 0;
		temp = value;
		value = temp + 1;
		return temp;
	}
}
