CommerceThreads 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(); } }
- A. true
- B. false
- C. truetrue
- D. falsefalse
Correct Answer: D
Which of these method is used to begin the execution of a thread?
- A. run()
- B. start()
- C. runThread()
- D. startThread()
Correct Answer: B
Which of this method is used to find out that a thread is still running or not?
- A. run()
- B. Alive()
- C. isAlive()
- D. checkRun()
Correct Answer: C
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(); } }
- A. Thread[New Thread,0,main]
- B. Thread[New Thread,1,main]
- C. Thread[New Thread,5,main]
- D. Thread[New Thread,10,main]
Correct Answer: D
Which of the following is a correct constructor for thread?
- A. Thread(Runnable a, String str)
- B. Thread(int priority)
- C. Thread(Runnable a, int priority)
- D. Thread(Runnable a, ThreadGroup t)
Correct Answer: A
Which of these method wakes up all the threads?
- A. wakeAll()
- B. notify()
- C. start()
- D. notifyAll()
Correct Answer: D
What decides thread priority?
- A. Process
- B. Process scheduler
- C. Thread
- D. Thread scheduler
Correct Answer: D
Thread priority in Java is?
- A. Integer
- B. Float
- C. double
- D. long
Correct Answer: A
What is true about time slicing?
- A. Time slicing is OS service that allocates CPU time to available runnable thread
- B. Time slicing is the process to divide the available CPU time to available runnable thread
- C. Time slicing depends on its implementation in OS
- D. Time slicing allocates more resources to thread
Correct Answer: B
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?
- A. wait()
- B. notify()
- C. notifyAll()
- D. sleep()
Correct Answer: A
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"); } } }
- A. true
- B. false
- C. Main thread interrupted
- D. None of the mentioned
Correct Answer: B
Which of the following stops execution of a thread?
- A. Calling SetPriority() method on a Thread object
- B. Calling notify() method on an object
- C. Calling wait() method on an object
- D. Calling read() method on an InputStream object
Correct Answer: B