PRACTICE • LEARN • GROW
Module 11: Multithreading - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 11: Multithreading - Final Quiz Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Why is implementing the
Runnable interface generally preferred over extending the Thread class?
A.
Runnable runs faster because it bypasses the JVM
B.
Because Java permits only single class inheritance, implementing Runnable leaves the class free to extend another class, promoting cleaner separation of task and worker
C.
Thread class is deprecated in modern Java
D.
Runnable does not require overriding the run() method
Explanation & Key
Correct Answer:
2
What happens if you invoke t.run() directly instead of t.start() on a Thread object?
Thread t = new Thread(() -> System.out.println("Running"));
t.run();
A.
A new OS thread is spawned asynchronously
B.
The run() method executes synchronously on the current calling thread, without creating or launching a new concurrent thread
C.
Throws IllegalThreadStateException immediately
D.
The JVM deadlocks
Explanation & Key
Correct Answer:
3
Which state sequence represents the full lifecycle of a Java thread as depicted in Figure 11.1?
A.
New -> Running -> Runnable -> Terminated
B.
New -> Runnable -> Running -> (Blocked/Waiting) -> Terminated
C.
Active -> Idle -> Terminated
D.
Created -> Sleeping -> Destroyed
Explanation & Key
Correct Answer:
4
What is a "race condition" in concurrent programming?
A.
A competition between two compilers to produce faster bytecode
B.
A flaw where multiple threads access and mutate shared data concurrently without synchronization, making the final state dependent on unpredictable execution timing
C.
When a thread runs faster than the CPU clock speed
D.
When memory garbage collection causes a program freeze
Explanation & Key
Correct Answer:
5
What does the
synchronized keyword acquire before executing the protected block or method?
A.
A system semaphore in the OS kernel
B.
The intrinsic monitor lock of the specified object instance (or Class object if static)
C.
Exclusive access to the entire physical RAM
D.
A network socket token
Explanation & Key
Correct Answer:
6
What will happen if start() is called twice on the exact same Thread instance?
Thread t = new Thread(() -> {});
t.start();
t.start();
A.
The thread executes its task twice concurrently
B.
It throws java.lang.IllegalThreadStateException at runtime
C.
The second call is silently ignored
D.
The thread resets to its initial state
Explanation & Key
Correct Answer:
7
Which method causes the currently running thread to pause execution and yield CPU time for a specified number of milliseconds?
A.
Thread.sleep(millis)
B.
Thread.wait(millis)
C.
Thread.pause(millis)
D.
Thread.yield(millis)
Explanation & Key
Correct Answer:
8
What is printed by the following code utilizing t.join()?
Thread t = new Thread(() -> {
System.out.print("Task ");
});
t.start();
t.join();
System.out.print("Main");
A.
Main Task
B.
Task Main
C.
Main
D.
Task
Explanation & Key
Correct Answer:
9
What is the critical behavioral difference between
object.wait() and Thread.sleep() regarding monitor locks?
A.
Both methods release all acquired locks
B.
object.wait() releases the monitor lock on the object so other threads can enter; Thread.sleep() retains all acquired locks during its sleep duration
C.
Thread.sleep() releases locks while wait() holds locks
D.
Neither method has any relationship to locks
Explanation & Key
Correct Answer:
10
What guarantees does the
volatile keyword provide for a shared variable in Java?
A.
Atomicity of compound operations like count++
B.
Memory visibility (writes are flushed directly to main memory and immediately visible to other threads) and prevention of compiler/CPU instruction reordering
C.
Automatic monitor locking identical to synchronized
D.
Prevention of garbage collection for that variable
Explanation & Key
Correct Answer:
11
If Thread A enters an instance
synchronized void methodA() on an object, and Thread B attempts to call a public static synchronized void methodB() on the same class, will Thread B be blocked by Thread A?
A.
Yes, because synchronized methods on the same class always share a single lock
B.
No, because instance synchronized methods lock on the instance ('this'), while static synchronized methods lock on the Class object ('MyClass.class')
C.
Yes, static methods have lower thread priority
D.
It results in a deadlock
Explanation & Key
Correct Answer:
12
Which of the following is NOT one of Coffman's four mandatory conditions required for a Deadlock to occur?
A.
Mutual Exclusion (resources cannot be shared simultaneously)
B.
Hold and Wait (threads hold allocated resources while waiting for additional ones)
C.
No Preemption (resources cannot be forcibly confiscated from holding threads)
D.
Immediate Preemption (resources are automatically confiscated if another thread requests them)
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong