adplus-dvertising

Welcome to the Multithreading MCQs Page

Dive deep into the fascinating world of Multithreading with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Multithreading, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Multithreading, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Java Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Multithreading. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Java Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Multithreading. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Multithreading MCQs | Page 9 of 10

Explore more Topics under Java Programming

Q81.
Which two statements are true?

1. Deadlock will not occur if wait()/notify() is used
2. A thread will resume execution as soon as its sleep duration expires.
3. Synchronization can prevent two objects from being accessed by the same thread.
4. The wait() method is overloaded to accept a duration.
5. The notify() method is overloaded to accept a duration.
6. Both wait() and notify() must be called from a synchronized context.
Discuss
Answer: (c).4 and 6
Q82.
The following block of code creates a Thread using a Runnable target:

Runnable target = new MyRunnable();
Thread myThread = new Thread(target);

Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
Discuss
Answer: (c).public class MyRunnable implements Runnable{public void run(){}}
Discuss
Answer: (b).If a class has synchronized code, multiple threads can still access the nonsynchronized code.
Discuss
Answer: (b).If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.
Discuss
Answer: (a).The notifyAll() method must be called from a synchronized context.
Q86.
Which of the following line of code is suitable to start a thread ?
class X implements Runnable
{
 public static void main(String args[])
 {
 /* Missing code? */
 }
 public void run() {}
}
Discuss
Answer: (c).X run = new X(); Thread t = new Thread(run); t.start();
Q87.
What will be the output of the program?
class multithreaded_programing
{
 public static void main(String args[])
 {
  Thread t = Thread.currentThread();
  t.setName("New Thread");
  System.out.println(t);
 }
}
Discuss
Answer: (d).Thread[New Thread,5,main]
Q88.
Number of threads in below java program is:
public class ThreadExtended extends Thread {
 public void run() {
  System.out.println("Thread is running no");
 }
 public static void main(String[] args) 
 {
  ThreadExtended threadE = new ThreadExtended();
  threadE.start();
 }
}

a.

0

b.

1

c.

2

d.

3

Discuss
Answer: (c).2
Q89.
Which of these will create and start this thread?
public class MyRunnable implements Runnable
{
 public void run()
 {
  // some code here
 }
}
Discuss
Answer: (c).new Thread(new MyRunnable()).start();
Q90.
What is the priority of the thread in output of this program?
class multithreaded_programing
{
 public static void main(String args[])
 {
  Thread t = Thread.currentThread();
  t.setName("New Thread");
  System.out.println(t.getName());
 }
}
Discuss
Answer: (c).New Thread

Suggested Topics

Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!