public class UseCounter5 implements Runnable 
{
	Counter c;                         
	public UseCounter5() {
		c = new Counter(0);
	    Thread t1 = new Thread(this);
	    Thread t2 = new Thread(this);
	    t1.start();
	    t2.start();
	}

	public void run() {
        int val = 0;
        try {
            Thread.sleep(200);
		    val = c.getAndIncrement(); 
        } catch (InterruptedException ie) {}
		System.out.println("Value of counter = " + val);
	}
	
	public static void main(String[] args) {
		new UseCounter5();
	}
}

class Counter {
	private int value;

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

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

