Java Multithreading: 17 MCQs with answers
All 17 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 6 questions
Q1. What is a thread in Java?
BeginnerShow answer & explanation
A lightweight sub-process that runs concurrently with other threads
A thread is a lightweight sub-process, the smallest unit of execution that runs concurrently within a process.
Q2. Which of the following is the correct way to create a thread by implementing an interface?
BeginnerShow answer & explanation
Implement the Runnable interface
Implementing the Runnable interface is one of the two ways to create a thread; the other is extending the Thread class.
Q3. Which method is called to start a thread's execution?
BeginnerShow answer & explanation
start()
The start() method creates a new thread and calls the run() method inside that new thread.
Q4. What is the purpose of the run() method in a thread?
BeginnerShow answer & explanation
To contain the code that executes when the thread is running
The run() method holds the task that the thread performs; it is invoked by the start() method.
Q5. Which of the following is a benefit of multithreading?
BeginnerShow answer & explanation
It allows concurrent execution of tasks, improving resource utilization
Multithreading allows multiple tasks to run concurrently, which improves CPU utilization and responsiveness.
Q6. The start() method can be called multiple times on the same thread object.
BeginnerShow answer & explanation
False
Calling start() more than once on the same thread throws IllegalThreadStateException.
Building up · 8 questions
Q7. What is the default priority of a thread in Java?
IntermediateShow answer & explanation
5
The default priority of a thread is NORM_PRIORITY, which is 5.
Q8. Which method causes the currently executing thread to pause temporarily and allow other threads to execute?
IntermediateShow answer & explanation
yield()
yield() causes the current thread to pause, giving other threads of the same priority a chance to run.
Q9. What is the purpose of the join() method?
IntermediateShow answer & explanation
To wait for a thread to finish before continuing
join() makes the calling thread wait until the specified thread completes its execution.
Q10. Which keyword is used to make a method or block thread-safe?
IntermediateShow answer & explanation
synchronized
The synchronized keyword ensures that only one thread can access a method or block at a time, preventing race conditions.
Q11. What is a race condition?
IntermediateShow answer & explanation
A situation where multiple threads access shared data concurrently, leading to inconsistent results
A race condition occurs when multiple threads access shared data without proper synchronization, causing unpredictable outcomes.
Q12. Which method is used to interrupt a thread?
IntermediateShow answer & explanation
interrupt()
interrupt() sets the thread's interrupt status; the thread can then handle the interruption gracefully.
Q13. Which of the following is NOT a thread state in Java?
IntermediateShow answer & explanation
PAUSED
PAUSED is not a valid thread state; the valid states are NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED.
Q14. Synchronization is used to prevent race conditions.
IntermediateShow answer & explanation
True
Synchronization ensures that only one thread accesses a critical section at a time, preventing race conditions.
Topper level · 3 questions
Q15. What is the state of a thread when it is waiting for a monitor lock?
AdvancedShow answer & explanation
BLOCKED
A thread enters the BLOCKED state when it tries to enter a synchronized block but the lock is held by another thread.
Q16. What is the purpose of the volatile keyword?
AdvancedShow answer & explanation
To make a variable thread-safe by ensuring visibility of changes across threads
volatile ensures that changes to a variable are immediately visible to other threads, preventing caching issues.
Q17. What is a deadlock?
AdvancedShow answer & explanation
Two or more threads waiting indefinitely for each other's locks
Deadlock occurs when two or more threads are blocked forever, each waiting for a lock held by another.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages