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 code? class newthread extends Thread { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { try { t.join() System.out.println(t.getName()); } catch(Exception e) { System.out.print("Exception"); } } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }

  1. A. My Thread
  2. B. Thread[My Thread,5,main]
  3. C. Exception
  4. D. Runtime Error
Report Error

Which of these method of Thread class is used to Suspend a thread for a period of time?

  1. A. sleep()
  2. B. terminate()
  3. C. suspend()
  4. D. stop()
Report Error

Which of these method is used to implement Runnable interface?

  1. A. stop()
  2. B. run()
  3. C. runThread()
  4. D. stopThread()
Report Error

What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?

  1. A. 0 & 256
  2. B. 0 & 1
  3. C. 1 & 10
  4. D. 1 & 256
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 { System.out.print(obj1.t.equals(obj2.t)); } catch(Exception 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 these are types of multitasking?

  1. A. Process based
  2. B. Thread based
  3. C. Process and Thread based
  4. D. None of the mentioned
Report Error

What is the name of the thread in output in the following Java program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t.getPriority()); } }

  1. A. 0
  2. B. 1
  3. C. 4
  4. D. 5
Report Error

What is the name of the thread in output in the following Java program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t.isAlive()); } }

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

What will happen if two thread of the same priority are called to be processed simultaneously?

  1. A. Anyone will be executed first lexographically
  2. B. Both of them will be executed simultaneously
  3. C. None of them will be executed
  4. D. It is dependent on the operating system
Report Error

Deadlock is a situation when thread is waiting for other thread to release acquired object.

  1. A. True
  2. B. False
Report Error

What will be the output of the following Java code? class newthread extends Thread { newthread() { super("My Thread"); start(); } public void run() { System.out.println(this); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }

  1. A. My Thread
  2. B. Thread[My Thread,5,main]
  3. C. Compilation Error
  4. D. Runtime Error
Report Error

What requires less resources?

  1. A. Thread
  2. B. Process
  3. C. Thread and Process
  4. D. Neither Thread nor Process
Report Error