Commerce

Threads MCQs

Practice Threads MCQs for competitive exams.

Threads MCQs

Practice questions from this topic.

Which of this method can be used to make the main thread to be executed last among all the threads?

  1. A. stop()
  2. B. sleep()
  3. C. join()
  4. D. call()
Report Error

Which of these keywords are used to implement synchronization? 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 { obj1.t.wait(); System.out.print(obj1.t.isAlive()); } catch(Exception e) { System.out.print("Main thread interrupted"); } } }

  1. A. synchronize
  2. B. syn
  3. C. synch
  4. D. synchronized
Report Error

Which of these method wakes up the first thread that called wait()?

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

What will be the output of the following Java code? class newthread implements Runnable { 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

What will be the output of the following Java code? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { System.out.println(t.getName()); } } 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 will be the output of the following Java code? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } } 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 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 { obj1.t.wait(); System.out.print(obj1.t.isAlive()); } 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

What is true about threading?

  1. A. run() method calls start() method and runs the code
  2. B. run() method creates new thread
  3. C. run() method can be called directly without start() method being called
  4. D. start() method creates new thread and calls code written in run() method
Report Error

What will be the output of the following Java code? class newthread extends Thread { Thread t1,t2; 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

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

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

What will be the output of the following Java code? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { System.out.println(t); } } 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

Which of this method is used to avoid polling in Java?

  1. A. wait()
  2. B. notify()
  3. C. notifyAll()
  4. D. all of the mentioned
Report Error