[ The following post is incorrect and should be ignored. I'm leaving it here anyway only because Sergio's post won't make sense if I remove it. - Jim ]
I agree with you. They've shown the entire TestClass class, and the main(
String[]) method. There is no reason to think that other threads are involved in this problem. And more importantly, even if there
were other threads involved, the variable threadCounter was declared private, and there's no way for any other threads to interfere with its value. Unless they use reflection, of course... the standard exception to many, many, many statements about
Java. But that's outside the scope of that the
SCJP covers. The short answer is, the Enthuware answer is wrong, and should be ignored.
A longer answer might mention that ++ is not an atomic operation, and if Enthuware had written their question a little more intelligently, allowing other threads access... then the Enthuware answer might have been right. But it's not. Too bad.
[ May 20, 2007: Message edited by: Jim Yingst ]