Practice high-yield Programming & Software Development MCQs on Threads — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following constructor of class Thread is valid one?
Correct Answer: Option C — Thread(Runnable threadOb, String threadName)
Detailed Academic Explanation:
A. Thread(Runnable threadOb, int priority) This constructor is invalid because the Thread class does not have a constructor that takes a Runnable object and an int priority as arguments. B. Thread(int priority) This constructor is invalid because the Thread class does not have a constructor that takes only an int priority as an argument. C. Thread(Runnable threadOb, String threadName) This constructor is valid. It creates a new thread with the provided Runnable object and assigns it the specified name. D. Thread(String threadName, int priority) This constructor is invalid because the Thread class does not have a constructor that takes both a String thread name and an int priority as arguments. E. None of these This option is incorrect because option C, "Thread(Runnable threadOb, String threadName)," is a valid constructor for the Thread class. Therefore, the correct answer is: C. Thread(Runnable threadOb, String threadName)
💡Key Conceptual Anchor:Threads
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Analyze the following code: public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { } }
Correct Answer: Option A — The program does not compile because the start() method is not defined in the Test class.
Detailed Academic Explanation:
Code Analysis: 1. Implementing Runnable: The Test class implements the Runnable interface, which requires the implementation of the run() method. 2. Creating an Instance: In the main method, an instance of Test is created (Test t = new Test();). 3. Calling start() Method: The code then calls t.start();. However, start() is a method of the Thread class, not the Runnable interface. 4. Compilation Error: Since Test implements Runnable and not Thread, it does not inherit the start() method from Thread. Therefore, calling start() on an instance of Test causes a compilation error because the start() method is not defined in the Test class. Therefore, the correct option is A: The program does not compile because the start() method is not defined in the Test class .
💡Key Conceptual Anchor:Threads
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen when you attempt to compile and run the following code? public class Test extends Thread{ public static void main(String argv[]){ Test t = new Test(); t.run(); t.start(); } public void run(){ System.out.println("run-test"); } }
Correct Answer: Option A — run-test run-test
Detailed Academic Explanation:
t.run() Legal, but does not start a new thread , it is like a method call of a class Test BUT t.start() creates a thread and call run() method.
💡Key Conceptual Anchor:Threads
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen after compiling and running following code? class A implements Runnable{ public void run(){ System.out.println("run-a"); } } public class Test{ public static void main(String... args){ A a = new A(); Thread t = new Thread(a); t.start(); t.start(); } }
Correct Answer: Option D — Compilation succeed but Runtime Exception
Detailed Academic Explanation:
Once a thread has been started, it can never be started again. 2nd time t.start() throws java.lang.IllegalThreadStateException.
💡Key Conceptual Anchor:Threads
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Predict the output: class A implements Runnable{ public void run(){ try{ for(int i=0;i<4;i++){ Thread.sleep(100); System.out.println(Thread.currentThread().getName()); } }catch(InterruptedException e){ } } } public class Test{ public static void main(String argv[]) throws Exception{ A a = new A(); Thread t = new Thread(a, "A"); Thread t1 = new Thread(a, "B"); t.start(); t.join(); t1.start(); } }
Correct Answer: Option A — A A A A B B B B
Detailed Academic Explanation:
t.join(); means Threat t must finish before Thread t1 starts.
💡Key Conceptual Anchor:Threads
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output? class A extends Thread{ public void run(){ for(int i=0; i<2; i++){ System.out.println(i); } } } public class Test{ public static void main(String argv[]){ Test t = new Test(); t.check(new A(){}); } public void check(A a){ a.start(); } }
Correct Answer: Option C — 0 1
Detailed Academic Explanation:
Class A extends Thread means the anonymous instance that is passed to check() method has a start method which then calls the run method.
💡Key Conceptual Anchor:Threads
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen when you attempt to compile and run the following code? class A implements Runnable{ public void run(){ System.out.println("run-A"); } } public class Test{ public static void main(String argv[]){ A a = new A(); Thread t = new Thread(a); System.out.println(t.isAlive()); t.start(); System.out.println(t.isAlive()); } }
Correct Answer: Option A — false run-A true
Detailed Academic Explanation:
Once the start() method is called, the thread is considered to be alive.
💡Key Conceptual Anchor:Threads
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What notifyAll() method do?
Correct Answer: Option C — Wakes up all threads that are waiting on this object's monitor
Detailed Academic Explanation:
notifyAll() : Wakes up all threads that are waiting on this object's monitor.A thread waits on an object's monitor by calling one of the wait methods.
💡Key Conceptual Anchor:Threads
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output for the below code? class A implements Runnable{ public void run(){ System.out.println(Thread.currentThread().getName()); } } public class Test{ public static void main(String... args){ A a = new A(); Thread t = new Thread(a); t.setName("good"); t.start(); } }
Correct Answer: Option A — good
Detailed Academic Explanation:
Thread.currentThread().getName() return name of the current thread.
💡Key Conceptual Anchor:Threads
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Predict the output: public class Test extends Thread{ private int i; public void run(){ i++; } public static void main(String[] args){ Test a = new Test(); a.run(); System.out.print(a.i); a.start(); System.out.print(a.i); } }
Correct Answer: Option C — Prints
Detailed Academic Explanation:
Here, firstly the run() method of the object referred by a is directly invoked. When the run() method of a thread is invoked instead of the start() method, it is executed by the same thread as a conventional method. So it increments i to 1, now the output is 1. After this, the invocation of the start() method schedules a new thread of execution. Now it is impossible to predict whether the new thread will run first or the second print statement will be executed by the main thread first. So the result of the second print statement can be 1 or 2 depending on the scheduling of the 2 threads.
💡Key Conceptual Anchor:Threads
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of this method can be used to make the main thread to be executed last among all the threads?
Correct Answer: Option C — join()
Detailed Academic Explanation:
The join() method in Java is used to pause the execution of the current thread until the thread on which join() is called has finished executing. To ensure that the main thread executes last , we can call the join() method on all other threads in the main thread. This causes the main thread to wait for the completion of other threads before it proceeds. sleep() is used to pause a thread for a specific time, not to coordinate the order of thread completion. stop() is deprecated and unsafe. call() is not a valid method for controlling thread execution in this context.
💡Key Conceptual Anchor:Threads
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following stops execution of a thread?
Correct Answer: Option B — Calling notify() method on an object
Detailed Academic Explanation:
Understanding Thread Execution Control in Java Let's break down why one of these options stops a thread's execution. Option A: Calling SetPriority() method on a Thread object setPriority() is used to influence the scheduler to give a thread more or less CPU time. It doesn't stop the thread; it just suggests a priority. Option B: Calling notify() method on an object notify() is used for thread communication . It wakes up a single thread that's waiting on the object's monitor. It doesn't stop the currently running thread; it potentially allows another thread to run. Option C: Calling wait() method on an object wait() causes the current thread to pause its execution and enter a waiting state . The thread releases the lock on the object and waits until another thread calls notify() or notifyAll() on the same object. This is the correct answer. Option D: Calling read() method on an InputStream object read() is used to read data from an input stream . If no data is available, the thread might block temporarily until data becomes available. While it *can* appear to pause the thread, it's waiting for I/O, not explicitly stopping execution in the same way as wait() . The thread remains alive. In Summary: The wait() method directly suspends a thread's execution and places it in a waiting state, making Option C the correct answer.
💡Key Conceptual Anchor:Threads
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following will ensure the thread will be in running state?
Correct Answer: Option E — None of these
Detailed Academic Explanation:
Let's understand this question about threads in Java! The question asks us which of the given options will guarantee that a thread is in the running state . Option A: yield() yield() suggests to the Java Virtual Machine (JVM) that the current thread is willing to relinquish its current use of a processor. The JVM is free to ignore this suggestion. It doesn't *guarantee* the thread will stay running or give up the processor; it just offers a hint. Option B: notify() notify() is used for inter-thread communication. It wakes up a single thread that is waiting on the object's monitor. It doesn't directly put a thread into the running state; it makes a waiting thread *eligible* to run, but it might have to wait its turn. Option C: wait() wait() causes the current thread to *relinquish* the lock and enter the waiting state. The thread only becomes *eligible* to run again when another thread calls notify() or notifyAll() on the same object. So, wait() definitely does *not* ensure the thread is in the running state; it does the opposite! Option D: Thread.killThread() There is no standard Thread.killThread() method in Java for directly killing a thread in a safe way. This method is not a part of Java Thread API. Option E: None of these Since none of the options guarantees that a thread is in a running state by their use, hence Option E is correct Therefore, the answer is Option E: None of these.
💡Key Conceptual Anchor:Threads
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java program? class newthread extends Thread { Thread t; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }
Correct Answer: Option D — falsefalse
Detailed Academic Explanation:
In the given program, the class newthread extends Thread , and within its constructor, it creates two thread objects: t1 and t2 . Both threads are started with t1.start() and t2.start() , and they both execute the same run() method of the class instance because this is passed as the target. Inside the run() method, the priority of t2 is set to Thread.MAX_PRIORITY . However, this has no effect on the logic or output because thread priority only suggests execution preference to the scheduler. The key line is System.out.print(t1.equals(t2)); which checks if t1 and t2 are equal. Since t1 and t2 are two separate thread instances, the equals() method returns false . Because both threads run the same run() method, the output false is printed twice — once by each thread. Hence, the output is falsefalse .
💡Key Conceptual Anchor:Threads
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a thread in Java?
Correct Answer: Option A — A lightweight process that runs independently within a program
Detailed Academic Explanation:
A lightweight process that runs independently within a program is the correct answer to “What is a thread in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which interface is used to create a thread in Java?
Correct Answer: Option D — Runnable
Detailed Academic Explanation:
Runnable is the correct answer to “Which interface is used to create a thread in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the main advantage of using multithreading in Java programs?
Correct Answer: Option C — Improved program performance by utilizing multiple CPUs or CPU cores
Detailed Academic Explanation:
Improved program performance by utilizing multiple CPUs or CPU cores is the correct answer to “What is the main advantage of using multithreading in Java programs”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you create a new thread in Java by implementing the Runnable interface?
Correct Answer: Option B — Create a class that implements the Runnable interface and override the run() method
Detailed Academic Explanation:
Create a class that implements the Runnable interface and override the run() method is the correct answer to “How can you create a new thread in Java by implementing the Runnable interface”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the start() method in Java threads?
Correct Answer: Option C — It starts the execution of a new thread
Detailed Academic Explanation:
It starts the execution of a new thread is the correct answer to “What is the purpose of the start() method in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, can a thread be restarted after it has completed execution?
Correct Answer: Option D — No, a thread cannot be restarted once it has completed
Detailed Academic Explanation:
No, a thread cannot be restarted once it has completed is the correct answer to “In Java, can a thread be restarted after it has completed execution”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of calling the run() method directly instead of start() in Java threads?
Correct Answer: Option A — The run() method is executed in the current thread, not as a separate thread
Detailed Academic Explanation:
The run() method is executed in the current thread, not as a separate thread is the correct answer to “What is the result of calling the run() method directly instead of start() in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you achieve synchronization between threads in Java?
Correct Answer: Option D — By using the synchronized keyword or synchronized blocks
Detailed Academic Explanation:
By using the synchronized keyword or synchronized blocks is the correct answer to “How can you achieve synchronization between threads in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a race condition in multithreaded Java programs?
Correct Answer: Option C — A situation where multiple threads access shared data simultaneously, leading to unpredictable results
Detailed Academic Explanation:
A situation where multiple threads access shared data simultaneously, leading to unpredictable results is the correct answer to “What is a race condition in multithreaded Java programs”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the sleep() method in threads?
Correct Answer: Option B — It pauses the execution of the current thread for a specified duration
Detailed Academic Explanation:
It pauses the execution of the current thread for a specified duration is the correct answer to “In Java, what is the purpose of the sleep() method in threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the join() method in Java threads?
Correct Answer: Option C — It waits for a thread to complete its execution before moving on
Detailed Academic Explanation:
It waits for a thread to complete its execution before moving on is the correct answer to “What is the purpose of the join() method in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the difference between a thread's priority and its thread group's maximum priority?
Correct Answer: Option A — A thread's priority determines its relative importance, while the thread group's maximum priority sets an upper limit on thread priorities
Detailed Academic Explanation:
A thread's priority determines its relative importance, while the thread group's maximum priority sets an upper limit on thread priorities is the correct answer to “In Java, what is the difference between a thread's priority and its thread group's maximum priority”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you check if a thread is still running in Java?
Correct Answer: Option D — By using the isAlive() method
Detailed Academic Explanation:
By using the isAlive() method is the correct answer to “How can you check if a thread is still running in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, can you force a thread to stop its execution using the stop() method?
Correct Answer: Option C — Yes, but it is discouraged because it can leave the program in an inconsistent state
Detailed Academic Explanation:
Yes, but it is discouraged because it can leave the program in an inconsistent state is the correct answer to “In Java, can you force a thread to stop its execution using the stop() method”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the yield() method in Java threads?
Correct Answer: Option B — It suggests that the current thread should yield to other threads with the same priority
Detailed Academic Explanation:
It suggests that the current thread should yield to other threads with the same priority is the correct answer to “What is the purpose of the yield() method in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the interrupt() method in threads?
Correct Answer: Option C — It interrupts the normal execution of a thread, causing it to throw an InterruptedException
Detailed Academic Explanation:
It interrupts the normal execution of a thread, causing it to throw an InterruptedException is the correct answer to “In Java, what is the purpose of the interrupt() method in threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to declare a synchronized method in Java?
Correct Answer: Option D — synchronized
Detailed Academic Explanation:
synchronized is the correct answer to “Which keyword is used to declare a synchronized method in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is a daemon thread?
Correct Answer: Option A — A thread that runs in the background and does not prevent the program from exiting
Detailed Academic Explanation:
A thread that runs in the background and does not prevent the program from exiting is the correct answer to “In Java, what is a daemon thread”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you prevent multiple threads from accessing a critical section of code simultaneously in Java?
Correct Answer: Option D — By using synchronized blocks or methods
Detailed Academic Explanation:
By using synchronized blocks or methods is the correct answer to “How can you prevent multiple threads from accessing a critical section of code simultaneously in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the isDaemon() method in Java threads?
Correct Answer: Option C — It checks if a thread is a daemon thread
Detailed Academic Explanation:
It checks if a thread is a daemon thread is the correct answer to “What is the purpose of the isDaemon() method in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what happens when a thread encounters an uncaught exception and terminates abruptly?
Correct Answer: Option B — The JVM prints the exception trace and terminates the thread
Detailed Academic Explanation:
The JVM prints the exception trace and terminates the thread is the correct answer to “In Java, what happens when a thread encounters an uncaught exception and terminates abruptly”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of calling the setDaemon(true) method on a running thread in Java?
Correct Answer: Option C — It sets the thread as a daemon thread
Detailed Academic Explanation:
It sets the thread as a daemon thread is the correct answer to “What is the result of calling the setDaemon(true) method on a running thread in Java”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the isInterrupted() method in threads?
Correct Answer: Option D — It checks if a thread has been interrupted
Detailed Academic Explanation:
It checks if a thread has been interrupted is the correct answer to “In Java, what is the purpose of the isInterrupted() method in threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you handle exceptions in Java threads?
Correct Answer: Option A — By using try-catch blocks within the run() method
Detailed Academic Explanation:
By using try-catch blocks within the run() method is the correct answer to “How can you handle exceptions in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which class is used to create and manage thread groups?
Correct Answer: Option D — ThreadGroup
Detailed Academic Explanation:
ThreadGroup is the correct answer to “In Java, which class is used to create and manage thread groups”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the setPriority() method in Java threads?
Correct Answer: Option C — It sets the priority of a thread
Detailed Academic Explanation:
It sets the priority of a thread is the correct answer to “What is the purpose of the setPriority() method in Java threads”. This question is standard in competitive examination syllabi for Threads.
💡Key Conceptual Anchor:Threads
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.