Hi,
PLs help with this,
class MyClass
{
static private int mycount = 0;
int yournumber;
private static synchronized int nextCount()
{
return ++mycount;
}
public void getYourNumber()
{
yournumber = nextCount();
}
}
The correct answer is "each
thread will get a unique number". Can someone explain why ? I think that as the "getYourNumber()" is not synchronized so many thread can access it at the same time and can get the same number. I am assuming that as "nextCount" is private so no thread is accessing it directly to get the unique count.
thanks,
Sarika.