There was a post and after i submitted the answer it got deleted. Since i have put in the effort am still posting it
1) hardy.sleep(1000); -> is same as Thread.sleep(1000): This will simply cause the currently executing
thread to sleep for 1 second. This shows static methods must always be invoked using class name to avoid confusion.
2)
Once both the threads are started, who gets to go first is upto scheduler hence "A" and "D" can get displayed in any order.
So the result could include
A
D
or
D
A
3)"B" will never get displayed in this code since no one is interrupting laurel thread.
a) In case hardy thread had a reference to laurel thread
b) laurel goes to sleep.
c) Before laurel wakes up , hardy interrupts laurel by invoking
laurel.interrupt() then "B" would have displayed.
4) laurel.wait(10000); This causes the laurel thread to
a) Wait on "laurel" object: Unless some one notifies on laurel object by invoking laurel.notify() [ This again might not cause the above thread to wake up , if there are more than one threads waiting on laurel"] or notifyAll().
OR
b) Wait for 10seconds and wakes up.
Since in this code noone is notifying , the only possiblity for laurel thread to comeout is after waiting for 10 seconds.
Further since again no one is interrupting laurel thread during its waiting period "E" would never be displayed.
5) Now these leaves us with C and F.
Once laurel & hardy threads come out of sleeping and waiting respectively they have one statement each System.out.println("C"); and System.out.println("F"); respectively to execute, before calling it a day.
The order in which these statements are executed is again depends on Thread schedular.
hence the result can include either
C
F
or
F
C
Hence the final result could be
D A C F
OR
A D C F
OR
A D C F
OR
D A F C
Hope this clears your doubt.