a)in pre b)pre in c)in post pre d)in pre post e)pre in post f)pre post in
The only answer i get when i compile and run this program several times is option e. And my other guess is option f. Can someone tell what the answer is with some explanation please. Thanks! [ May 05, 2008: Message edited by: sridhar row ]
I think the only correct option is e(pre, in & post) because even if the child thread starts executing its run method before the main thread prints "pre" the child thread is in sleep mode for 2 secs and during this time the main thread will execute its code because there is no other live thread. After that the main thread is blocked for the child thread to complete and hence "in" will be printed.
Although the answer will be e most of the times or you can say that 99.9999% of the time, but still it quite ambiguous that during that 2 second main thread will execute or not, we don't know how the JVM and OS treats thread ! so we can not say with 100% surety that answer will be e every time and again the proof of reverse can not be given, this is entirely theory.