Two doubts:
1. Placing run() inside main() generates "illegal start of expression error"? So why can't run() be placed inside main()?

2.With the above code I am getting the output as A C D B. Why B comes last is because of join(). But what I'm unable to understand is that on invoking start() shouldn't run() get called immediately thus generating the output as C D A B?

Help please..Thanks

Edited by WaltP: Requests for help are NOT Code Snippets

5 Years
Discussion Span
Last Post by rahul.ch
  1. You can't define one method inside another - that's just the Java langauge definition. (except when the second method is inside an inner class defined inside a method...)
  2. After executing t.start()) you have two threads withe same priority and no synchronisation, so you have no control or knowledge about the order in which they will be executed.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.