Vidyalelo
Java Programming · all questions

Threads
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

105

Questions

5/6

Page

Pick an option on a question to see the right answer and solution.

Deadlock is a situation when thread is waiting for other thread to release acquired object.

Select an option to see the answer and solution.

What will happen if two thread of the same priority are called to be processed simultaneously?

Select an option to see the answer and solution.

What is the name of the thread in output in the following Java program?
class multithreaded_programing
{
    public static void main(String args[])
    {
        Thread t = Thread.currentThread();
        System.out.println(t.isAlive());        
    }
}

Select an option to see the answer and solution.

What is the name of the thread in output in the following Java program?
class multithreaded_programing
{
    public static void main(String args[])
    {
        Thread t = Thread.currentThread();
        System.out.println(t.getPriority());        
    }
}

Select an option to see the answer and solution.

What is multithreaded programming?

Select an option to see the answer and solution.

Which of these are types of multitasking?

Select an option to see the answer and solution.

What will be the output of the following Java 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");
        }
    }
}

Select an option to see the answer and solution.

What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?

Select an option to see the answer and solution.

Which of these method is used to implement Runnable interface?

Select an option to see the answer and solution.

Which of these method of Thread class is used to Suspend a thread for a period of time?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class newthread extends Thread 
{
Thread t;
newthread()
    {
  t = new Thread(this,"My Thread");
  t.start();
}
public void run()
    {
        try
        {
            t.join()   
      System.out.println(t.getName());
        }
        catch(Exception e)
        {
        System.out.print("Exception");
        }
}
}
class multithreaded_programing
{
    public static void main(String args[])
    {
        new newthread();        
    }
}

Select an option to see the answer and solution.

What is the priority of the thread in the following Java Program?
class multithreaded_programing 
{
    public static void main(String args[])
    {
        Thread t = Thread.currentThread();
        System.out.println(t);        
    }
}

Select an option to see the answer and solution.

Which of these method is used to explicitly set the priority of a thread?

Select an option to see the answer and solution.

Which of these method waits for the thread to terminate?

Select an option to see the answer and solution.

What is synchronization in reference to a thread?

Select an option to see the answer and solution.

What does not prevent JVM from terminating?

Select an option to see the answer and solution.

What is the priority of the thread in output in the following Java program?
class multithreaded_programing
{
    public static void main(String args[])
    {
        Thread t = Thread.currentThread();
        t.setName("New Thread");
        System.out.println(t.getName());        
    }
}

Select an option to see the answer and solution.

Which of these method of Thread class is used to find out the priority given to a thread?

Select an option to see the answer and solution.

What is the name of the thread in the following Java Program?
class multithreaded_programing
{
    public static void main(String args[])
    {
        Thread t = Thread.currentThread();
        System.out.println(t);        
    }
}

Select an option to see the answer and solution.

Which function of pre defined class Thread is used to check weather current thread being checked is still running?

Select an option to see the answer and solution.