Home » JAVA Programming » Multithreading » Question
  1. What is the output of this program?
    class newthread implements Runnable 
    {
    Thread thread;
    newthread()
    {
    thread = new Thread(this,"New Thread created...");
    thread.start();
    }
    public void run()
    {
    thread.setPriority(Thread.MAX_PRIORITY);
    System.out.println(thread);
    }
    }
    public class multithreaded_Example
    {
    public static void main(String args[])
    {
    new newthread();
    }
    }
    1. Thread[New Thread created...,10,main]
    2. [New Thread created...,10,main]
    3. New Thread created...
    4. [New Thread created...,10,main]Thread
    5. None of these
Correct Option: A

Thread thread has been made with default priority value 5 but in run method the priority has been explicitly changed to MAX_PRIORITY of class thread, that is 10 by code ‘thread.setPriority(Thread.MAX_PRIORITY);’ using the setPriority function of thread t.



Your comments will be displayed only after manual approval.