Java Multiple Choice Questions & Answers on Thread class for Freshers

https://www.computersprofessor.com/2018/01/java-multiple-choice-questions-answers.html
1. Which of these class is used to make a thread?
a) String
b) System
c) Thread
d) Runnable
Answer: c
Explanation: Thread class is used to make threads in java, Thread encapsulates a thread of execution. To create a new thread the program will either extend Thread or implement the Runnable interface.
2. Which of these interface is implemented by Thread class?
a) Runnable
b) Connections
c) Set
d) MapConnections
Answer: a
3. Which of these method of Thread class is used to find out the priority given to a thread?
a) get()
b) ThreadPriority()
c) getPriority()
d) getThreadPriority()
Answer: c
5. 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()
Answer: a
6. Which function of pre defined class Thread is used to check weather current thread being checked is still running?
a) isAlive()
b) Join()
c) isRunning()
d) Alive()
Answer: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.
7. What is the 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);
}
}
a) Thread[5,main]
b) Thread[New Thread,5]
c) Thread[main,5,main]
d) Thread[New Thread,5,main]
Answer: d
8. 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());
}
}
a) main
b) Thread
c) New Thread
d) Thread[New Thread,5,main]
b) Thread
c) New Thread
d) Thread[New Thread,5,main]
Answer: c
Explanation: The getName() function is used to obtain the name of the thread, in this code the name given to thread is ‘New Thread’.
9. 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());
}
}
a) 0
b) 1
c) 4
d) 5
b) 1
c) 4
d) 5
Answer: d
Explanation: The default priority given to a thread is 5.
10. 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());
}
}
a) 0
b) 1
c) true
d) false
b) 1
c) true
d) false
Answer: c
Explanation: Thread t is seeded to currently program, hence when you run the program the thread becomes active & code ‘t.isAlive’ returns true.