CommerceThreads 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(); } }
- A. My Thread
- B. Thread[My Thread,5,main]
- C. Exception
- D. Runtime Error
Correct Answer: D
Which of these method of Thread class is used to Suspend a thread for a period of time?
- A. sleep()
- B. terminate()
- C. suspend()
- D. stop()
Correct Answer: A
Which of these method is used to implement Runnable interface?
- A. stop()
- B. run()
- C. runThread()
- D. stopThread()
Correct Answer: B
What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?
- A. 0 & 256
- B. 0 & 1
- C. 1 & 10
- D. 1 & 256
Correct Answer: C
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"); } } }
- A. true
- B. false
- C. Main thread interrupted
- D. None of the mentioned
Correct Answer: B
Which of these are types of multitasking?
- A. Process based
- B. Thread based
- C. Process and Thread based
- D. None of the mentioned
Correct Answer: C
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()); } }
- A. 0
- B. 1
- C. 4
- D. 5
Correct Answer: D
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()); } }
- A. 0
- B. 1
- C. true
- D. false
Correct Answer: C
What will happen if two thread of the same priority are called to be processed simultaneously?
- A. Anyone will be executed first lexographically
- B. Both of them will be executed simultaneously
- C. None of them will be executed
- D. It is dependent on the operating system
Correct Answer: D
Deadlock is a situation when thread is waiting for other thread to release acquired object.
- A. True
- B. False
Correct Answer: A
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(); } }
- A. My Thread
- B. Thread[My Thread,5,main]
- C. Compilation Error
- D. Runtime Error
Correct Answer: B
What requires less resources?
- A. Thread
- B. Process
- C. Thread and Process
- D. Neither Thread nor Process
Correct Answer: A