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-4 | Java Thread State MCQ | Also see:- Define Thread in Java Multithreading Interview Questions
Q1) Exception will be raised in which thread?
class MyThread extends Thread {
public void run() {
Thread.currentThread().setName("KnowProgram");
System.out.println(10/0);
}
}
public class Test {
public static void main(String[] args) {
MyThread mt = new MyThread();
mt.start();
}
}
a) Exception in thread “KnowProgram”
b) Exception in thread “Thread-0”
c) Exception in thread “main”
d) None of these
View Answer
Answer:- a) Exception in thread “KnowProgram”Q2) Find the output of the below program?
class MyThread extends Thread {}
public class Test {
public static void main(String[] args) {
MyThread mt = new MyThread();
mt.setName("KP");
mt.start();
System.out.print(mt.getName()+" ");
MyThread mt1 = new MyThread();
mt1.setName("KP");
mt1.start();
System.out.println(mt.getName());
}
}
a) KP KP
b) KP thread-0
c) KP thread-1
d) Compile time error or Run-time Exception
View Answer
Answer:- a) KP KPWe can create multiple threads with the same name.
Q3) Which of the following are thread states?
a) NEW
b) RUNNABLE
c) BLOCKED
d) All of these
View Answer
Answer:- d) All of theseQ4) What will be the output of the below program?
class MyThread extends Thread { }
public class Test {
public static void main(String[] args) {
Thread t = new Thread();
System.out.println(t.getState());
t.start();
}
}
a) NEW
b) RUNNABLE
c) BLOCKED
d) None of these
View Answer
Answer:- a) NEWQ5) What will be the output of the below program?
public class Test {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getState());
}
}
a) NEW
b) RUNNABLE
c) BLOCKED
d) None of these
View Answer
Answer:- b) RUNNABLEQ6) What will be the output of the below program?
class MyThread extends Thread {
public void run() {
int count = 0;
for (int i=0; i<10; i++) {
count += i;
}
}
}
public class Test {
public static void main(String[] args) throws Exception {
Thread t = new Thread();
t.start();
Thread.sleep(1000);
System.out.println(t.getState());
}
}
a) NEW
b) RUNNABLE
c) BLOCKED
d) TERMINATED
View Answer
Answer:- d) TERMINATEDQ7) What will be the output of the below program?
class MyThread extends Thread { }
public class Test {
public static void main(String[] args) {
Thread t = new Thread();
System.out.println(t.isAlive());
t.start();
}
}
a) true
b) false
c) Compile time error
d) None of these
View Answer
Answer:- b) falseQ8) What will be the output of the below program?
class MyThread extends Thread { }
public class Test {
public static void main(String[] args) {
Thread t = new Thread();
t.start();
System.out.println(t.isAlive());
}
}
a) true
b) false
c) Compile time error
d) None of these
View Answer
Answer:- a) trueQ9) What will be the output of the below program?
class MyThread extends Thread {
public void run() {
int count = 0;
for (int i=0; i<10; i++) {
count += i;
}
}
}
public class Test {
public static void main(String[] args) throws Exception {
Thread t = new Thread();
t.start();
Thread.sleep(1000);
System.out.println(t.isAlive());
}
}
a) true
b) false
c) Compile time error
d) None of these
View Answer
Answer:- b) falseQ10) If the thread is in a RUNNABLE state then isAlive() method return?
a) true
b) false
c) Compile time error
d) None of these
View Answer
Answer:- a) trueIf 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!