join() is called on Thread-1(that means, reference a) and called by mainthread.That means mainthread will wait until the thread-1(a) will die. So thread-1 is completed first holding 1 value.then that(1) value is printed for a.i.
I wanted to make sure that I got the join() method correctly.Am i correct...
posted 9 years ago
Yes you are correct.
Here, a.join() means main thread will wait for a to complete. By this way, a will successfully assign 1 to i before main thread prints it.