Java Multiple Choice Questions & Answers on Multithreading Basics for Freshers

https://www.computersprofessor.com/2018/01/java-multiple-choice-questions-answers_2.html
1. What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously.
b) It’s a process in which two or more parts of same process run simultaneously.
c) Its a process in which many different process are able to access same information.
d) Its a process in which a single process can access information from many sources.
Answer: b
Explanation: multithreaded programming a process in which two or more parts of same process run simultaneously.
2. Which of these are types of multitasking?
a) Process based
b) Thread based
c) Process and Thread based
d) None of the mentioned
Answer: c
Explanation: There are two types of multitasking: Process based multitasking and Thread based multitasking.
3. Which of these packages contain all the Java’s built in exceptions?
a) java.io
b) java.util
c) java.lang
d) java.net
Answer: c
4. Thread priority in Java is?
a) Integer
b) Float
c) double
d) long
Answer: a
Explanation: Java assigns to each thread a priority that determines hoe that thread should be treated with respect to others. Thread priority are integers that specify relative priority of one thread to another.
5. What will happen if two thread of same priority are called to be processed simultaneously?
a) Any one will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the operating system.
Answer: d
Explanation: In cases where two or more thread with same priority are competing for CPU cycles, different operating system handle this situation differently. Some execute them in time sliced manner some depending on the thread they call.
6. Which of these statements is incorrect?
a) By multithreading CPU’s idle time is minimized, and we can take maximum use of it.
b) By multitasking CPU’s idle time is minimized, and we can take maximum use of it.
c) Two thread in Java can have same priority
d) A thread can exist only in two states, running and blocked.
Answer: d
Explanation: Thread exist in several states, a thread can be running, suspended, blocked, terminated & ready to run.
7. What is the output of this program?
class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t);
}
}
a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,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();
System.out.println(t);
}
}
a) 4
b) 5
c) 0
d) 1
b) 5
c) 0
d) 1
Answer: b
Explanation: The output of program is Thread[main,5,main], in this priority assigned to the thread is 5. Its the default value. Since we have not named the thread they are named by the group to they belong i:e main method.
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);
}
}
a) main
b) Thread
c) System
d) None of the mentioned
b) Thread
c) System
d) None of the mentioned
Answer: a
Explanation: The output of program is Thread[main,5,main], Since we have not explicitly named the thread they are named by the group to they belong i:e main method. Hence they are named ‘main’.
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.