The output does come out to be 0123, but it is not predictable. This is because after calling t.start(), it is upto the scheduler to decide whether the main thread should begin execution first or the child thread.
Usually,
Java gives the child thread the same priority as the thread in which it was created.
If the scheduler decides to give priority to the child thread, the output would not remain the same (See code output below).
Just to demonstrate the above to you,
Here is the output from 2 consecutive runs of the program:
Output 1:
Main thread's priority is 5
In Child 1
In Child 2
In Child 3
In Main 4
In Main 5
In Main 6
Child thread's priority is 5
6
Output 2:
Main thread's priority is 5
In Main 1
In Main 2
In Main 3
In Child 4
In Child 5
In Child 6
Child thread's priority is 5
6
[ August 15, 2006: Message edited by: Aniket Patil ]