Difficulty: Easy
Correct Answer: MyThread foo
Explanation:
Introduction / Context:
This question combines constructor side effects with method overriding. The superclass MyThread prints in its constructor and defines two run methods: run() and an overloaded run(String). The anonymous subclass created in main overrides run().
Given Data / Assumptions:
Concept / Approach:
Thread.start() always invokes the no-argument run() polymorphically. Overloads such as run(String) are not considered by the thread machinery. Therefore, after construction prints, the overridden run() in the anonymous class runs and prints " foo".
Step-by-Step Solution:
Verification / Alternative check:
Replace println with print and observe spacing differences, but the token order remains MyThread then foo.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing overloading with overriding; Thread looks only for run().
Final Answer:
MyThread foo
Discussion & Comments