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-1 | Define a Thread in Java MCQ-1 | Also see:- Define Thread in Java Multithreading Interview Questions
Q1) The process of executing multiple independent sub-tasks in one main task at a time concurrently is called?
a) Multitasking
b) Multithreading
c) Both
d) None of these
View Answer
Answer:- b) MultithreadingQ2) The process of executing multiple tasks at a time concurrently is called?
a) Multitasking
b) Multithreading
c) Both
d) None of these
View Answer
Answer:- a) MultitaskingMCQ on Creating/Defining a Thread in Java
Q3) If we want to start a thread, which method should be called?
a) start()
b) run()
c) None of these
d) Both
View Answer
Answer:- a) start()Q4) What will be the output of the below program?
class MyThread extends Thread {
public void run() {
System.out.print("run() ");
}
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
System.out.print("main() ");
t.run();
}
}
a) run() main()
b) main() run()
c) Sometimes (a) and Sometimes (b)
d) None of these.
View Answer
Answer:- b) main() run()The run() method of MyThread class will be executed as a normal method call. Hence output is fixed.
Q5) If we want to start a thread then which method must be called by the programmer?
a) run()
b) start()
c) both start() and run()
d) None of these
View Answer
Answer:- b) start()As a programmer we need to call the start() method. The start() method of Thread class has to perform many important jobs to start a new thread. After registering the thread, the thread will be started and the run() method will be called by the start() method. Without calling start() method thread will not be started.
Q6) Find the output of the below program?
class MyThread extends Thread {
public void run() {
System.out.println("No-arg run()");
}
public void run(int i) {
System.out.println("int-arg run()");
}
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
}
}
a) No-arg run()
b) Int-arg run()
c) Sometimes No-arg run(), and sometimes Int-arg run()
d) Compile time error
View Answer
Answer:- a) No-arg run()The start() method of Thread class calls run() method with no argument. If a thread wants to execute another overloaded form of run() method then those methods must be called from run() method explicitly.
Q7) Find the output of the below program?
class MyThread extends Thread {
public void run() {
System.out.print("No-arg ");
run(15);
}
public void run(int i) {
System.out.print("int-arg ");
}
}
public class Test {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
}
}
a) No-arg int-arg
b) int-arg No-arg
c) No output
d) None of these
View Answer
Answer:- b) int-arg No-argQ8) Find the output of the below program?
class MyThread extends Thread {
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
}
}
a) Compile time error
b) Run time error
c) No output
d) None of these
View Answer
Answer:- c) No outputSince the run() method is not available in child class (MyThread) therefore it will be executed from parent class (Thread). The run() method of the Thread class has an empty implementation. Therefore we wonβt get any output.
Q9) What is the possible output of the below program?
class MyThread extends Thread {
public void start() {
System.out.print("start() Method, ");
}
public void run() {
System.out.print("run() Method, ");
}
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
System.out.println("Main Thread, ");
}
}
a) Main Thread, start() method,
b) Main Thread, run() method,
c) run() method, Main Thread,
d) start() method, Main Thread,
View Answer
Answer:- d) start() method, Main Thread,Since we have overridden the start() method in MyThread class, therefore the start() method of Thread class will not get a chance to execute. In this case the start() method of MyThread will be executed like a normal method call. New thread is not created. Complete output produced by only the main thread, therefore output will be fixed.
Q10) What is the possible output of the below program?
class MyThread extends Thread {
public void start() {
super.start();
System.out.println("start() ");
}
public void run() {
System.out.println("run() ");
}
}
public class ThreadDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
}
}
a) run()
b) start()
c) start() run()
d) run() start()
View Answer
Answer:- c) start() run()In the MyThread class, the start() method is overridden but it calls super.start() method therefore the start() method of the Thread class will be also executed. Hence other than the main thread, a new thread also will be created, and it will call run() method.
If 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!