Commerce

Threads MCQs

Practice Threads MCQs for competitive exams.

Threads MCQs

Practice questions from this topic.

In Java, can you directly access the run() method of a Thread object?

  1. A. Only if the thread is marked as "final"
  2. B. Yes, but it will execute in the current thread, not as a separate thread
  3. C. Only if the thread is marked as "static"
  4. D. None of These
Report Error

What is the purpose of the setPriority() method in Java threads?

  1. A. It starts a new thread
  2. B. It resumes a paused thread
  3. C. It sets the priority of a thread
  4. D. It synchronizes threads
Report Error

In Java, which class is used to create and manage thread groups?

  1. A. GroupManager
  2. B. ThreadController
  3. C. ThreadManager
  4. D. ThreadGroup
Report Error

How can you handle exceptions in Java threads?

  1. A. By using try-catch blocks within the run() method
  2. B. By using the stop() method
  3. C. By ignoring exceptions in threads
  4. D. By using the yield() method
Report Error

In Java, what is the purpose of the isInterrupted() method in threads?

  1. A. It checks if a thread is a daemon thread
  2. B. It checks if a thread is waiting
  3. C. It checks if a thread is running
  4. D. It checks if a thread has been interrupted
Report Error

What is the result of calling the setDaemon(true) method on a running thread in Java?

  1. A. It resumes the thread
  2. B. It pauses the thread
  3. C. It sets the thread as a daemon thread
  4. D. It stops the thread immediately
Report Error

In Java, what happens when a thread encounters an uncaught exception and terminates abruptly?

  1. A. The thread is paused indefinitely
  2. B. The JVM prints the exception trace and terminates the thread
  3. C. The thread resumes execution without any impact
  4. D. None of These
Report Error

What is the purpose of the isDaemon() method in Java threads?

  1. A. It checks if a thread is currently running
  2. B. It checks if a thread is sleeping
  3. C. It checks if a thread is a daemon thread
  4. D. It checks if a thread is waiting
Report Error

How can you prevent multiple threads from accessing a critical section of code simultaneously in Java?

  1. A. By using the wait() method
  2. B. By using the start() method multiple times
  3. C. By creating more threads to access the critical section
  4. D. By using synchronized blocks or methods
Report Error

In Java, what is a daemon thread?

  1. A. A thread that runs in the background and does not prevent the program from exiting
  2. B. A thread that is always in a waiting state
  3. C. A thread that cannot be interrupted
  4. D. A thread that runs on a separate CPU
Report Error

Which keyword is used to declare a synchronized method in Java?

  1. A. sync
  2. B. lock
  3. C. thread-safe
  4. D. synchronized
Report Error

In Java, what is the purpose of the interrupt() method in threads?

  1. A. It resumes the thread
  2. B. It pauses the thread
  3. C. It interrupts the normal execution of a thread, causing it to throw an InterruptedException
  4. D. It stops the thread permanently
Report Error