Difficulty: Easy
Correct Answer: By extending the Thread class or by implementing the Runnable interface and then starting a Thread with that runnable
Explanation:
Introduction / Context:
To use multithreading in Java, you need a way to define the work a thread will perform and then start that work concurrently with other tasks. Java provides two classic approaches for creating threads, both of which are common in interviews and exam questions. This question asks you to identify those two standard techniques for creating and starting threads in Java.
Given Data / Assumptions:
Concept / Approach:
Java offers two primary ways to create a thread. The first is to create a subclass of Thread and override its run() method with the code the thread should execute, then call start() on the instance. The second is to implement the Runnable interface in a separate class or use a lambda expression, then pass an instance of that runnable to a new Thread object and call start(). In both cases, calling start() asks the JVM to create a new call stack and execute run() concurrently. Synchronisation and other concurrency tools then manage interactions between threads.
Step-by-Step Solution:
Step 1: Identify extending Thread as one standard approach: class MyThread extends Thread { public void run() { /* work */ } }.Step 2: Recognise that you create an instance of MyThread and call myThread.start() to begin concurrent execution.Step 3: Identify implementing Runnable as the second standard approach: class MyTask implements Runnable { public void run() { /* work */ } }.Step 4: Create a new Thread with this runnable, for example new Thread(new MyTask()).start(), which again runs the run() method concurrently.Step 5: Conclude that these two methods, extending Thread and implementing Runnable, are the accepted standard ways to start new threads in core Java, matching option A.
Verification / Alternative check:
Java tutorials and official documentation consistently present these two techniques as the basic options for creating threads. Later frameworks such as executor services still rely on Runnable or Callable tasks at their core. Running simple examples shows that overriding run() in a Thread subclass or supplying a Runnable both lead to concurrent execution when you call start(). This confirms that option A accurately describes the standard approaches to starting threads.
Why Other Options Are Wrong:
Option B suggests calling main() multiple times, which does not create new threads; it simply restarts the entry point in the same thread or process. Option C refers to synchronized methods, which control access to shared resources but do not create new threads by themselves. Option D confuses multithreading with reading files sequentially using java.io.File, which does not introduce concurrency. Therefore, only option A correctly lists the two standard thread creation techniques.
Common Pitfalls:
A common pitfall is overriding run() but accidentally calling run() directly instead of start(), which executes the code in the current thread and does not create any concurrency. Another mistake is extending Thread when you really want to separate task logic from thread management; implementing Runnable is often more flexible because it allows you to reuse the task with different threading frameworks. Understanding both techniques helps you write cleaner, more maintainable multithreaded code in Java.
Final Answer:
Correct answer: By extending the Thread class or by implementing the Runnable interface and then starting a Thread with that runnable
Discussion & Comments