Java MCQ – Home
Java Basic MCQ
➤ Java Hello World MCQ
➤ Find Java Keywords
➤ Java Identifier Quiz
➤ Java Data Types Quiz
➤ If-Else MCQ in Java-1
➤ If-Else MCQ in Java-2
Object class MCQ
➤ Object Class Quiz
➤ equals() Method Quiz
➤ Hashcode Value Quiz
➤ toString() Method Quiz
➤ Clone() Method Quiz
Multithreading MCQ
➤ Define a Thread-1
➤ Define a Thread-2
➤ Get/set ThreadName
➤ Thread State MCQ
➤ Thread Priority MCQ
➤ Yield(), join() & sleep()
➤ Synchronization MCQ
➤ Interthread Comms
➤ Deadlock, Daemon
Exception Handling
➤ Exception Handling-1
➤ Exception Handling-2
➤ Exception Handling-3
➤ Java try-catch MCQ-1
➤ Java try-catch MCQ-2
➤ Java try-catch MCQ-3
➤ Nested try-catch MCQ
➤ throw Keyword MCQ
➤ finally Block MCQ-1
➤ finally Block MCQ-2
➤ throws Keyword MCQ
Generics MCQ
➤ Java Generics Quiz-1
➤ Java Generics Quiz-2
➤ Java Generics Quiz-3
Collection Framework
➤ Collections Quiz-1
➤ Collections Quiz-2
➤ ArrayList MCQ-1
➤ ArrayList MCQ-2
➤ LinkedList MCQ
➤ Vector Stack MCQ
➤ Java Cursors MCQ
➤ Java TreeSet MCQ
➤ TreeSet & Comparator
Java Multithreading MCQ Part-5Â | Thread Priority MCQ | Also see:-Â Define Thread in Java Multithreading Interview Questions
Q1) What is the valid range of priority of a thread in Java multi-threading?
a) 1 to 10
b) 0 to 10
c) 0 to 9
d) 1 to 9
View Answer
Answer:- a) 1 to 10Q2) Which is the minimum priority of the Thread?
a) Thread.LOW_PRIORITY
b) Thread.MIN_PRIORITY
c) Thread.NORM_PRIORITY
d) Thread.MINIMUM_PRIORITY
View Answer
Answer:- b) Thread.MIN_PRIORITYQ3) What is the value of Thread.NORM_PRIORITY?
a) 1
b) 5
c) 6
d) 9
View Answer
Answer:- b) 5Q4) Which of these are invalid thread priorities?
1) Thread.MIN_PRIORITY
2) Thread.HIGH_PRIORITY
3) Thread.NORM_PRIORITY
4) Thread.LOW_PRIORITY
5) 0
6) 1
7) 10
Options:-
a) 2 & 5
b) 2, 4 & 5
c) 2, 3, 4 & 5
d) All are valid
View Answer
Answer:- b) 2, 4 & 5Among these options Thread.HIGH_PRIORITY, Thread.LOW_PRIORITY and 0 are the invalid thread priority.
Q5) There are 4 threads given below priorities. If they are waiting for execution then what can be the order of getting a chance to execute?
Thread | Priority |
t1 | 8 |
t2 | 6 |
t3 | 7 |
t4 | 4 |
a) t1 > t2 > t3 > t4
b) t4 > t3 > t2 > t1
c) t1 > t3 > t2 > t4
d) t4 > t2 > t3 > t1
View Answer
Answer:- c) t1 & t3 & t2 & t4The thread having high priority will get a chance first.
Q6) Which of the following method calls is invalid?
a) t1.setPriority(5)
b) t1.setPriority(1)
c) t1.setPriority(12)
d) t1.setPriority(9)
View Answer
Answer:- c) t1.setPriority(12)In the setPriority(int p) the passed value must belong to the thread priority range (1 to 10) else we will get an IllegalArgumentException.
Q7) What is the default priority of a thread?
a) 1
b) 5
c) Inherit from Parent
d) Random value within 1 to 10
View Answer
Answer:- c) Inherit from ParentThe default priority of the thread is inherited from the parent thread. Child thread will get the same priority as parent thread.
Q8) What is the default priority of the main thread?
a) 1
b) 5
c) 10
d) Random value within 1 to 10
View Answer
Answer:- b) 5Q9) Find the output of the below program?
public class Test extends Thread {
public static void main(String[] args) {
System.out.print(Thread.currentThread().getPriority()+" ");
Thread.currentThread().setPriority(9);
Test t = new Test();
System.out.println(t.getPriority());
}
}
a) 5 9
b) 5 5
c) 9 5
d) 5 10
View Answer
Answer:- a) 5 9The default priority of the main thread is 5. The thread t1 is created by the main thread therefore the main thread is the parent thread and t1 is the child thread. The thread priority of the main thread is set to 9, then the child thread is created. The priority of the child thread inherits from the parent thread. Hence the priority of child thread is 9.
Q10) Find the output of the below program?
public class Test {
public static void main(String[] args) {
System.out.println(Thread.MAX_PRIORITY);
}
}
a) 9
b) 10
c) 0
d) 1
View Answer
Answer:- b) 10If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!