Difficulty: Easy
Correct Answer: public class MyRunnable implements Runnable{public void run(){}}
Explanation:
Introduction / Context:
To construct a Thread with a Runnable target, the argument must implement the java.lang.Runnable interface. The interface declares one method: public void run().
Given Data / Assumptions:
Concept / Approach:
A class can implement an interface, not extend it. When implementing Runnable, the run method must be declared public to satisfy the interface’s public abstract signature. A package-private run() fails to implement the interface method due to reduced visibility.
Step-by-Step Solution:
Verification / Alternative check:
Compile Option C and pass new MyRunnable() into new Thread(target); code compiles and runs.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that interface methods are implicitly public and must be implemented with public visibility.
Final Answer:
public class MyRunnable implements Runnable{public void run(){}}
Discussion & Comments