CommerceThreads MCQs
Practice Threads MCQs for competitive exams.
Threads MCQs
Practice questions from this topic.
What is the purpose of the yield() method in Java threads?
- A. It suspends the current thread indefinitely
- B. It suggests that the current thread should yield to other threads with the same priority
- C. It sets the priority of the current thread
- D. None of These
Correct Answer: B
In Java, can you force a thread to stop its execution using the stop() method?
- A. No, the stop() method is deprecated and cannot be used
- B. Only if the thread is marked as "final"
- C. Yes, but it is discouraged because it can leave the program in an inconsistent state
- D. Only if the thread is marked as "static"
Correct Answer: C
How can you check if a thread is still running in Java?
- A. By using the runStatus() method
- B. By using the isThreadAlive() method
- C. By using the isRunning() method
- D. By using the isAlive() method
Correct Answer: D
In Java, what is the difference between a thread's priority and its thread group's maximum priority?
- A. A thread's priority determines its relative importance, while the thread group's maximum priority sets an upper limit on thread priorities
- B. A thread's priority is always higher than the thread group's maximum priority
- C. A thread's priority is the same as the thread group's maximum priority
- D. A thread's priority is unrelated to the thread group's maximum priority
Correct Answer: A
What is the purpose of the join() method in Java threads?
- A. It synchronizes threads
- B. It resumes a paused thread
- C. It waits for a thread to complete its execution before moving on
- D. It starts a new thread
Correct Answer: C
In Java, what is the purpose of the sleep() method in threads?
- A. It terminates all threads in the program
- B. It pauses the execution of the current thread for a specified duration
- C. It resumes the execution of a thread
- D. None of These
Correct Answer: B
What is a race condition in multithreaded Java programs?
- A. A situation where threads synchronize perfectly
- B. A situation where threads never finish executing
- C. A situation where multiple threads access shared data simultaneously, leading to unpredictable results
- D. A situation where threads throw exceptions
Correct Answer: C
How can you achieve synchronization between threads in Java?
- A. By using the interrupt() method
- B. By using the wait() and notify() methods
- C. By using multiple catch blocks
- D. By using the synchronized keyword or synchronized blocks
Correct Answer: D
What is the result of calling the run() method directly instead of start() in Java threads?
- A. The run() method is executed in the current thread, not as a separate thread
- B. It starts a new thread and executes the run() method
- C. It stops the thread immediately
- D. It suspends the thread
Correct Answer: A
In Java, can a thread be restarted after it has completed execution?
- A. Yes, a thread can be restarted multiple times
- B. Only if the thread is marked as "final"
- C. Only if the thread is marked as "static"
- D. No, a thread cannot be restarted once it has completed
Correct Answer: D
What is the purpose of the start() method in Java threads?
- A. It resumes the execution of a thread
- B. It suspends the execution of a thread
- C. It starts the execution of a new thread
- D. It stops the execution of a thread
Correct Answer: C
How can you create a new thread in Java by implementing the Runnable interface?
- A. Create an object of the Thread class
- B. Create a class that implements the Runnable interface and override the run() method
- C. Use the start() method of the main thread
- D. None of These
Correct Answer: B