Java MCQ Questions - Threads
This section focuses on the "Threads" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
1. What is the name of the method used to start a thread execution?
A. run();
B. init();
C. start();
D. resume();
View Answer
Ans : C
Explanation: The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
2. Which cannot directly cause a thread to stop executing?
A. Calling the SetPriority() method on a Thread object.
B. Calling read() method on an InputStream object.
C. Calling notify() method on an object.
D. Calling the wait() method on an object.
View Answer
Ans : C
Explanation: notify() - wakes up a single thread that is waiting on this object's monitor.
3. Which of the following will directly stop the execution of a Thread?
A. notify()
B. notifyall()
C. wait()
D. exits synchronized code
View Answer
Ans : C
Explanation: . wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
4. Which function of pre defined class Thread is used to check weather current thread being checked is still running?
A. isAlive()
B. Alive()
C. isRunning()
D. Join()
View Answer
Ans : A
Explanation: isAlive() function is defined in class Thread, it is used for implementing multithreading and to check whether the thread called upon is still running or not.
5. Which method must be defined by a class implementing the java.lang.Runnable interface?
A. public void run()
B. void run()
C. void run(int priority)
D. public void start()
View Answer
Ans : A
Explanation: In an interface all methods are abstract by default therefore they must be overridden by the implementing class. The Runnable interface only contains 1 method, the void run() method therefore it must be implemented.
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?
A. After thread A is notified, or after two seconds.
B. Two seconds after thread A is notified.
C. After the lock on B is released, or after two seconds.
D. Two seconds after lock B is released.
View Answer
Ans : A
Explanation: Either of the two events (notification or wait time expiration) will make the thread become a candidate for running again.
7. Which will contain the body of the thread?
A. main();
B. stop();
C. start();
D. run();
View Answer
Ans : D
Explanation: The run() method to a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread.
8. Which class or interface defines the wait(), notify(),and notifyAll() methods?
A. Object
B. Class
C. Runnable
D. Thread
View Answer
Ans : A
Explanation: The Object class defines these thread-specific methods.
9. Which of these method of Thread class is used to find out the priority given to a thread?
A. ThreadPriority()
B. get()
C. getPriority()
D. getThreadPriority()
View Answer
Ans : C
Explanation: getPriority() method of Thread class is used to find out the priority given to a thread.
10. Which of these method of Thread class is used to Suspend a thread for a period of time?
A. stop()
B. sleep()
C. terminate()
D. suspend()
View Answer
Ans : B
Explanation: sleep() method of Thread class is used to Suspend a thread for a period of time.
Also check :
Discussion