Java Multithreading Questions and Answers

Related Topics:

Java Programming : Java Multithreading

Java Multithreading Interview Questions and Answers for freshers as well as experienced. Multithreading MCQ questions can be helpful to crack java Interview in various companies.
1. Which of these class is used to make a thread?
[A] String
[B] System
[C] Thread
[D] Runnable

Answer: C. Thread

Explanation:

Thread class is used to make threads in java, Thread encapsulates a thread of execution. To create a new thread the program will either extend Thread or implement the Runnable interface
2. Which of these interface is implemented by Thread class?
[A] Runnable
[B] Connections
[C] Set
[D] MapConnections

Answer: A. Runnable

Explanation:

Runnable interface used by Thread class
3. Which function of pre defined class Thread is used to check weather current thread being checked is still running?
[A] isAlive()
[B] Join()
[C] isRunning()
[D] Alive()

Answer: A. isAlive()

Explanation:

isAlive() function is defined in class Thread, it is used for implementing multithreading and to check whether the thread called upon is still running or not.
4. What is the 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);        
        }
    }
[A] Thread[5,main]
[B] Thread[New Thread,5]
[C] Thread[main,5,main]
[D] Thread[New Thread,5,main]

Answer: D. Thread[New Thread,5,main]

Explanation:

Thread set for 5 second
5. 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());        
        }
    }
[A] main
[B] Thread
[C] New Thread
[D] Thread[New Thread,5,main]

Answer: C. New Thread

Explanation:

The getName() function is used to obtain the name of the thread, in this code the name given to thread is ‘New Thread’.
6. 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

Answer: D. 5

Explanation:

The default priority given to a thread is 5.
7. Which methods are utilized to control the access to an object in multi threaded programming
[A] Asynchronized methods
[B] Synchronized methods
[C] Serialized methods
[D] None of above

Answer: B. Synchronized methods

Explanation:

Synchronized methods is used for multiprogramming
8. Which of the following is used to force each thread to reconcile its working copy of a variable with the master copy in main memory?
[A] synchronized
[B] transient
[C] volatile
[D] native

Answer: C. volatile

Explanation:

A field might be shared between two or more threads. Each thread is allowed to maintain a working copy of the field. If the threads do not reconcile the working copies then each might be working with a different value.
9. What is multithreaded programming?
[A] It’s a process in which two different processes run simultaneously.
[B] It’s a process in which two or more parts of same process run simultaneously.
[C] Its a process in which many different process are able to access same information.
[D] Its a process in which a single process can access information from many sources.

Answer: B. It’s a process in which two or more parts of same process run simultaneously.

Explanation:

multithreaded programming a process in which two or more parts of same process run simultaneously.
10. Which of these are types of multitasking?
[A] Process based
[B] Thread based
[C] Process and Thread based
[D] None of the mentioned

Answer: C. Process and Thread based

Explanation:

There are two types of multitasking: Process based multitasking and Thread based multitasking.

Comments: (Your feedback is valuable to us)

sakthivel 1 year ago Reply

nice post


Gidraf Kungu 1 year ago Reply

good


;