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

4/6

Page

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

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

Select an option to see the answer and solution.

Which of these method wakes up the first thread that called wait()?

Select an option to see the answer and solution.

Which of these keywords are used to implement synchronization?
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
        {
            obj1.t.wait();	
            System.out.print(obj1.t.isAlive());
        }
        catch(Exception e)
        {
  System.out.print("Main thread interrupted");
        }
    }
}

Select an option to see the answer and solution.

Which of this method can be used to make the main thread to be executed last among all the threads?

Select an option to see the answer and solution.

Which of the following stops execution of a thread?

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
        {
            Thread.sleep(1000);	
            System.out.print(obj1.t.isAlive());
        }
        catch(InterruptedException e)
        {
        System.out.print("Main thread interrupted");
        }
    }
}

Select an option to see the answer and solution.

Which of these method is used to tell the calling thread to give up a monitor and go to sleep until some other thread enters the same monitor?

Select an option to see the answer and solution.

What is true about time slicing?

Select an option to see the answer and solution.

Thread priority in Java is?

Select an option to see the answer and solution.

What decides thread priority?

Select an option to see the answer and solution.

Which of the following will ensure the thread will be in running state?

Select an option to see the answer and solution.

Which of these method wakes up all the threads?

Select an option to see the answer and solution.

Which of the following is a correct constructor for thread?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of this method is used to find out that a thread is still running or not?

Select an option to see the answer and solution.

Which of these statement is incorrect?

Select an option to see the answer and solution.

Which of these method is used to begin the execution of a thread?

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;
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();        
    }
}

Select an option to see the answer and solution.

What requires less resources?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class newthread extends Thread 
{
newthread()
    {
  super("My Thread");
  start();
}
public void run()
    {
  System.out.println(this);
}
}
class multithreaded_programing
{
    public static void main(String args[])
    {
        new newthread();        
    }
}

Select an option to see the answer and solution.