public class UseCounter1 extends Thread {
	Counter c;                         
	public UseCounter1() {
		c = new Counter(0);
        Thread t[] = new Thread[10];
		for (int i = 0; i < 10; i++) {
			t[i] = new Thread(this);
		}
    for (int i = 0; i < 10; i++) {
      t[i].start();
    }
	}

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

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