Multithreading


  1. What is the output of this program?
    public class multithreading_Example
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    thread.setName("Thread one");
    System.out.println(thread);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Thread[Thread one,5,main]


  1. What is the priority of the thread in output of this program?
    public class multithreaded_PriorityExample
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    thread.setName("Thread One");
    System.out.println(thread.getPriority());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The getPriority() function is used to obtain the priority of the thread, in this code the priority given to thread is ‘5’.



  1. What is the name of the thread in output of this program?
    public class multithreading_NameExample
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    thread.setName("Thread One");
    System.out.println(thread.getName());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The getName() function is used to obtain the name of the thread, in this code the name given to thread is ‘Thread One’.


  1. What is the output of the thread in output of this program?
    public class Output
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    System.out.println(thread.isAlive());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Thread t is seeded to currently program, hence when you run the program the thread becomes active & code ‘thread.isAlive’ returns true.



  1. What is multithreaded programming?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Multithreaded programming a process in which two or more parts of the same process run simultaneously.