Java - Threads Question and Answer

Java - Threads Question and Answer
1. What is the name of the method used to start a thread execution?
  • init();
  • start();
  • run();
  • resume();
Show Answer
2. Which two are valid constructors for Thread?

    1  Thread(Runnable r, String name)
    2 Thread()
    3 Thread(int priority)
    4 Thread(Runnable r, ThreadGroup g)
    5 Thread(Runnable r, int priority)

  • 1 and 3
  • 2 and 4
  • 1 and 2
  • 2 and 5
Show Answer
3. Which three are methods of the Object class?

    notify();
    notifyAll();
    isInterrupted();
    synchronized();
    interrupt();
    wait(long msecs);
    sleep(long msecs);
    yield();
  • 1, 2, 4
  • 2, 4, 5
  • 1, 2, 6
  • 2, 3, 4
Show Answer
4. class X implements Runnable
{
    public static void main(String args[])
    {
        /* Missing code? */
    }
    public void run() {}
}

Which of the following line of code is suitable to start a thread ?
  • Thread t = new Thread(X);
  • Thread t = new Thread(X); t.start();
  • X run = new X(); Thread t = new Thread(run); t.start();
  • Thread t = new Thread(); x.run();
Show Answer
5. Which cannot directly cause a thread to stop executing?
  • Calling the SetPriority() method on a Thread object.
  • Calling the wait() method on an object.
  • Calling notify() method on an object.
  • Calling read() method on an InputStream object.
Show Answer
6. Which two of the following methods are defined
in class Thread?
 start()
    wait()
    notify()
    run()
    terminate()

  • 1 and 4
  • 2 and 3
  • 3 and 4
  • 2 and 4
Show Answer
7. Which three guarantee that a thread will leave the running state?

    yield()
    wait()
    notify()
    notifyAll()
    sleep(1000)
    aLiveThread.join()
    Thread.killThread()
  • 1, 2 and 4
  • 2, 5 and 6
  • 3, 4 and 7
  • 4, 5 and 7
Show Answer
8. Which of the following will directly stop the execution of a Thread?
  • wait()
  • notify()
  • notifyall(
  • exits synchronized code
Show Answer
9. Which method must be defined by a class implementing the java.lang.Runnable interface?
  • void run()
  • public void run()
  • public void start()
  • void run(int priority)
Show Answer
10. Which will contain the body of the thread?
  • run();
  • start();
  • stop();
  • main();
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test