Here are 10 essential multiple-choice questions on Java Thread Basics and Lifecycle, covering key concepts.
Question 1
Which of the following is the correct way to create a thread in Java?
Extending the Thread class
Implementing the Runnable interface
Both A and B
Using the Callable interface only
Question 2
What will be the output of the following code?
class MyThread extends Thread { public void run() { System.out.println("Thread is running"); } public static void main(String[] args) { MyThread t = new MyThread(); t.run(); } }
Thread is running
Compilation Error
No Output
Runtime Exception
Question 4
What is the initial state of a thread when it is created but not yet started?
NEW
RUNNABLE
BLOCKED
WAITING
Question 5
Which of the following statements about the Runnable interface is true?
It contains the start() method
It contains the run() method
It can only be implemented by a class that extends Thread
It cannot be used for multithreading
Question 6
What happens if start() is called twice on the same thread?
class MyThread extends Thread { public void run() { System.out.println("Running..."); } public static void main(String[] args) { MyThread t = new MyThread(); t.start(); t.start(); } }
Thread runs twice
Compiles and runs normally
Throws IllegalThreadStateException
No output
Question 7
Which of the following is NOT a valid thread state in Java?
NEW
TERMINATED
RUNNING
TIMED_WAITING
Question 8
What happens if sleep(1000) is called inside a thread?
Thread execution is paused for 1 second
Thread is terminated
Thread goes to NEW state
Thread execution continues immediately
Question 9
What will be the output of the following code?
class Geeks { public static void main(String[] args) { Thread t = new Thread(() -> System.out.println("Hello from Thread")); t.start(); } }
Hello from Thread
Compilation Error
No Output
Runtime Exception
Question 10
Which method is used to wait for a thread to finish execution?
wait()
sleep()
join()
yield()
There are 10 questions to complete.