Java Programming Multiple Choice Questions - Threads
This section 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.
1. What is the name of the method used to start a thread execution?
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?
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?
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?
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.
Which method must be defined by a class implementing the java.lang.Runnable interface?
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:
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
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?
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?
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?
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?
Explanation:sleep() method of Thread class is used to Suspend a thread for a period of time.
Also check :