This section of our 1000+ Java MCQs focuses on multithreading of Java Programming Language.
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) It’s a process in which many different process are able to access same information
d) It’s a process in which a single process can access information from many sources
View Answer
Explanation: Multithreaded programming a process in which two or more parts of the 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
View Answer
Explanation: There are two types of multitasking: Process based multitasking and Thread based multitasking.
3. Thread priority in Java is?
a) Integer
b) Float
c) double
d) long
View Answer
Explanation: Java assigns to each thread a priority that determines hoe that thread should be treated with respect to others. Thread priority is integers that specify relative priority of one thread to another.
4. What will happen if two thread of the same priority are called to be processed simultaneously?
a) Anyone 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
View Answer
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.
5. Which of these statements is incorrect?
a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Java can have the same priority
d) A thread can exist only in two states, running and blocked
View Answer
Explanation: Thread exist in several states, a thread can be running, suspended, blocked, terminated & ready to run.
6. What will be the output of the following Java code?
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]
View Answer
Explanation: None.
Output:
$ javac multithreaded_programing.java $ java multithreaded_programing Thread[main,5,main]
7. What is the priority of the thread in the following Java 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
View Answer
Explanation: The output of program is Thread[main,5,main], in this priority assigned to the thread is 5. It’s the default value. Since we have not named the thread they are named by the group to they belong i:e main method.
Output:
$ javac multithreaded_programing.java $ java multithreaded_programing Thread[main,5,main]
8. What is the name of the thread in the following Java 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
View Answer
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’.
Output:
$ javac multithreaded_programing.java $ java multithreaded_programing Thread[main,5,main]
Sanfoundry Global Education & Learning Series – Java Programming Language.
- Practice Programming MCQs
- Apply for Java Internship
- Practice Information Technology MCQs
- Practice BCA MCQs
- Check Java Books