250+ TOP MCQs on Multithreading Basics and Answers

Java MCQs on Basics of 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

Answer: b
Clarification: 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

Answer: c
Clarification: 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

Answer: a
Clarification: 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

Answer: d
Clarification: 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

Answer: d
Clarification: 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?

  1.     class multithreaded_programing
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             Thread t = Thread.currentThread();
  6.             System.out.println(t);        
  7.         }
  8.     }

a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]

Answer: d
Clarification: 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?

  1.     class multithreaded_programing 
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             Thread t = Thread.currentThread();
  6.             System.out.println(t);        
  7.         }
  8.     }

a) 4
b) 5
c) 0
d) 1

Answer: b
Clarification: 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?

  1.     class multithreaded_programing
  2.     {
  3.         public static void main(String args[])
  4.         {
  5.             Thread t = Thread.currentThread();
  6.             System.out.println(t);        
  7.         }
  8.     }

a) main
b) Thread
c) System
d) None of the mentioned

Answer: a
Clarification: 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]

Leave a Reply

Your email address will not be published. Required fields are marked *