Difficulty: Easy
Correct Answer: new Thread(new MyRunnable()).start();
Explanation:
Introduction / Context:There are two common ways to create threads in Java: extend Thread or implement Runnable. This question focuses on the Runnable approach.
Given Data / Assumptions:
MyRunnable implements Runnable and overrides run().Concept / Approach:To execute a Runnable on a new thread, wrap the Runnable in a Thread and call start() on the Thread instance.
Step-by-Step Solution:
1) Construct aThread with the Runnable: new Thread(new MyRunnable()).2) Call start() to spawn the new thread; the JVM then calls run() on that thread.Verification / Alternative check:Calling run() directly executes on the current thread, not a new one.
Why Other Options Are Wrong:
Runnable is an interface, not a constructor parameter like that.run() directly on the new Thread object constructed with a type token (also invalid usage).Runnable has no start() method.Common Pitfalls:Confusing start() with run() and trying to call start() on a Runnable instead of a Thread.
Final Answer:new Thread(new MyRunnable()).start();
Discussion & Comments