Threads in Java MCQs

@T-Bone

This question paper focuses on the "Threads" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

This question paper focuses on the "Threads" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

Questions

1. What is the name of the method used to start a thread execution?

Mark the correct option

2. Which cannot directly cause a thread to stop executing?

Mark the correct option

3. Which of the following will directly stop the execution of a Thread?

Mark the correct option

4. Which function of pre defined class Thread is used to check weather current thread being checked is still running?

Mark the correct option

5. Which method must be defined by a class implementing the java.lang.Runnable interface?

Mark the correct option

6. Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU?

Mark the correct option

7. Which will contain the body of the thread?

Mark the correct option

8. Which class or interface defines the wait(), notify(),and notifyAll() methods?

Mark the correct option

9. Which of these method of Thread class is used to find out the priority given to a thread?

Mark the correct option

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

Mark the correct option

11. Which of the following line of code is suitable to start a thread ? class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} }

Mark the correct option

12. What will be the output of the program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("New Thread"); System.out.println(t); } }

Mark the correct option

13. Number of threads in below java program is: public class ThreadExtended extends Thread { public void run() { System.out.println("Thread is running no"); } public static void main(String[] args) { ThreadExtended threadE = new ThreadExtended(); threadE.start(); } }

Mark the correct option

14. which of these will create and start this thread? public class MyRunnable implements Runnable { public void run() { // some code here } }

Mark the correct option

15. What is the priority of the thread in output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("New Thread"); System.out.println(t.getName()); } }

Mark the correct option

16. What will be the output of the program? class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); t.start(); System.out.print("one. "); t.start(); System.out.print("two. "); } public void run() { System.out.print("Thread "); } }

Mark the correct option

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

Mark the correct option

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

Mark the correct option

19. The following block of code creates a Thread using a Runnable target:Which of the following classes can be used to create the target, so that the preceding code compiles correctly? Runnable target = new MyRunnable(); Thread myThread = new Thread(target);

Mark the correct option

20. The static method Thread.currentThread() returns a reference to the currently executing Thread object. What is the result of this code? class Test { public static void main(String [] args) { printAll(args); } public static void printAll(String[] lines) { for(int i = 0; i < lines.length; i++) { System.out.println(lines[i]); Thread.currentThread().sleep(1000); } } }

Mark the correct option

21. What is multithreaded programming?

Mark the correct option

22. Which of these are types of multitasking?

Mark the correct option

23. Thread priority in Java is?

Mark the correct option

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

Mark the correct option

25. Which of these statements is incorrect?

Mark the correct option

26. What requires less resources?

Mark the correct option

27. What does not prevent JVM from terminating?

Mark the correct option

28. What decides thread priority?

Mark the correct option

29. What is true about time slicing?

Mark the correct option

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

Mark the correct option