Difficulty: Easy
Correct Answer: 0..1..2..
Explanation:
Introduction / Context:
A Thread can take any Runnable, and Thread itself implements Runnable. If you pass a Thread (that overrides run()) as the target to another Thread, the outer Thread will invoke the target’s run() just like any Runnable. This is legal though unusual.
Given Data / Assumptions:
Concept / Approach:
Starting x results in x’s internal run() delegating to the target Runnable’s run(), which is t.run(). Therefore, the overridden run() in MyThread executes on thread x and prints 0..1..2..
Step-by-Step Solution:
Verification / Alternative check:
If main had called t.start() instead, you would still see 0..1..2.. (on a different thread) and possibly two sets if both were started.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming a Thread cannot be used as a Runnable target; expecting an exception or double printing.
Final Answer:
0..1..2..
Discussion & Comments