Commerce

Threads MCQs

Practice Threads MCQs for competitive exams.

Threads MCQs

Practice questions from this topic.

What will be the output of the following Java program? class newthread extends Thread { Thread t; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }

  1. A. true
  2. B. false
  3. C. truetrue
  4. D. falsefalse
Report Error

Which of these method is used to begin the execution of a thread?

  1. A. run()
  2. B. start()
  3. C. runThread()
  4. D. startThread()
Report Error

Which of this method is used to find out that a thread is still running or not?

  1. A. run()
  2. B. Alive()
  3. C. isAlive()
  4. D. checkRun()
Report Error

What will be the output of the following Java code? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { t.setPriority(Thread.MAX_PRIORITY); System.out.println(t); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }

  1. A. Thread[New Thread,0,main]
  2. B. Thread[New Thread,1,main]
  3. C. Thread[New Thread,5,main]
  4. D. Thread[New Thread,10,main]
Report Error

Which of the following is a correct constructor for thread?

  1. A. Thread(Runnable a, String str)
  2. B. Thread(int priority)
  3. C. Thread(Runnable a, int priority)
  4. D. Thread(Runnable a, ThreadGroup t)
Report Error

Which of these method wakes up all the threads?

  1. A. wakeAll()
  2. B. notify()
  3. C. start()
  4. D. notifyAll()
Report Error

What decides thread priority?

  1. A. Process
  2. B. Process scheduler
  3. C. Thread
  4. D. Thread scheduler
Report Error

Thread priority in Java is?

  1. A. Integer
  2. B. Float
  3. C. double
  4. D. long
Report Error

What is true about time slicing?

  1. A. Time slicing is OS service that allocates CPU time to available runnable thread
  2. B. Time slicing is the process to divide the available CPU time to available runnable thread
  3. C. Time slicing depends on its implementation in OS
  4. D. Time slicing allocates more resources to thread
Report Error

Which of these method is used to tell the calling thread to give up a monitor and go to sleep until some other thread enters the same monitor?

  1. A. wait()
  2. B. notify()
  3. C. notifyAll()
  4. D. sleep()
Report Error

What will be the output of the following Java program? class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { Thread.sleep(1000); System.out.print(obj1.t.isAlive()); } catch(InterruptedException e) { System.out.print("Main thread interrupted"); } } }

  1. A. true
  2. B. false
  3. C. Main thread interrupted
  4. D. None of the mentioned
Report Error

Which of the following stops execution of a thread?

  1. A. Calling SetPriority() method on a Thread object
  2. B. Calling notify() method on an object
  3. C. Calling wait() method on an object
  4. D. Calling read() method on an InputStream object
Report Error