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 5 of 10

Q41.
What is the output of this program?
    class newthread implements Runnable
    {
	Thread t;
	newthread()
        {
	    t = new Thread(this,"New Thread");
	    t.start();
	}
	public void run()
        {
	    t.setPriority(Thread.MAX_PRIORITY);	
            System.out.println(t);
	}
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            new newthread();        
        }
    }
Discuss
Answer: (d).Thread[New Thread,10,main].
Q42.
What is the output of this program?
    class newthread implements Runnable
    {
	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();        
        }
    }
Discuss
Answer: (d).falsefalse
Q43.
What is the name of the thread in output of this program?
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            Thread t = Thread.currentThread();
            System.out.println(t.getPriority());        
        }
    }

a.

0

b.

1

c.

4

d.

5

Discuss
Answer: (d).5
Q44.
What is the name of the thread in output of this program?
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            Thread t = Thread.currentThread();
            System.out.println(t.isAlive());        
        }
    }
Discuss
Answer: (c).true
Q45.
What is the output of this program?
    class newthread extends Thread
    {
	Thread t;
	String name;
	newthread(String threadname)
        {
	    name = threadname;
	    t = new Thread(this,name);
	    t.start();
	}
	public void run()
        {
        }
 
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
	    newthread obj1 = 	 new newthread("one");
	    newthread obj2 =	 new newthread("two");
            try
            {
                 System.out.print(obj1.t.equals(obj2.t));
            }
            catch(Exception e)
            {
	    System.out.print("Main thread interrupted");
            }
        }
    }
Discuss
Answer: (b).false
Q46.
What is the output of this 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();        
        }
    }
Discuss
Answer: (d).falsefalse
Q47.
Which two of the following methods are defined in class Thread?

1. start()
2. wait()
3. notify()
4. run()
5. terminate()
Discuss
Answer: (a).1 and 4
Q48.
Which three guarantee that a thread will leave the running state?

1. yield()
2. wait()
3. notify()
4. notifyAll()
5. sleep(1000)
6. aLiveThread.join()
7. Thread.killThread()
Discuss
Answer: (b).2, 5 and 6
Q49.
Which of the following will directly stop the execution of a Thread?
Discuss
Answer: (a).wait()
Q50.
Which method must be defined by a class implementing the java.lang.Runnable interface?
Discuss
Answer: (b).public void run()
Page 5 of 10

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!