posted 19 years ago
You are assuming that the start() method invokes and completes a.run() before the System.out.println( a.i ) is executed. However, you have no control over thread scheduling, so what's happening here is that System.out.println( a.i ) is executing before the run() method.
To confirm this, add the following line to the An run method:
Here, you'll see:
Note the '0' before the run print statement.
Hope that helps...
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4 all those years ago...)