Which statement correctly creates a Java thread from a class that implements Runnable and starts it running?
Java Programming
Threads
Difficulty: Easy
Choose an option
-
Anew Runnable(MyRunnable).start();
-
Bnew Thread(MyRunnable).run();
-
Cnew Thread(new MyRunnable()).start();
-
Dnew MyRunnable().start();
Answer
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:
MyRunnableimplementsRunnableand overridesrun().
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:
- Option A → invalid constructor call;
Runnableis an interface, not a constructor parameter like that. - Option B → calls
run()directly on the newThreadobject constructed with a type token (also invalid usage). - Option D →
Runnablehas nostart()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();