logo

CuriousTab

CuriousTab

Discussion


Home Java Programming Threads Comments

  • Question
  • Which class or interface defines the wait(), notify(),and notifyAll() methods?


  • Options
  • A. Object
  • B. Thread
  • C. Runnable
  • D. Class

  • Correct Answer
  • Object 

    Explanation
    The Object class defines these thread-specific methods.

    Option B, C, and D are incorrect because they do not define these methods. And yes, the Java API does define a class called Class, though you do not need to know it for the exam.


    Threads problems


    Search Results


    • 1. Which of the following will not directly cause a thread to stop?

    • Options
    • A. notify()
    • B. wait()
    • C. InputStream access
    • D. sleep()
    • Discuss
    • 2. Which method must be defined by a class implementing the java.lang.Runnable interface?

    • Options
    • A. void run()
    • B. public void run()
    • C. public void start()
    • D. void run(int priority)
    • Discuss
    • 3. Which method registers a thread in a thread scheduler?

    • Options
    • A. run();
    • B. construct();
    • C. start();
    • D. register();
    • Discuss
    • 4. Which two of the following methods are defined in class Thread?

      1. start()
      2. wait()
      3. notify()
      4. run()
      5. terminate()

    • Options
    • A. 1 and 4
    • B. 2 and 3
    • C. 3 and 4
    • D. 2 and 4
    • Discuss
    • 5. Which cannot directly cause a thread to stop executing?

    • Options
    • A. Calling the SetPriority() method on a Thread object.
    • B. Calling the wait() method on an object.
    • C. Calling notify() method on an object.
    • D. Calling read() method on an InputStream object.
    • Discuss
    • 6. Which will contain the body of the thread?

    • Options
    • A. run();
    • B. start();
    • C. stop();
    • D. main();
    • Discuss
    • 7. Assume the following method is properly synchronized and called from a thread A on an object B:

      wait(2000);

      After calling this method, when will the thread A become a candidate to get another turn at the CPU?


    • Options
    • A. After thread A is notified, or after two seconds.
    • B. After the lock on B is released, or after two seconds.
    • C. Two seconds after thread A is notified.
    • D. Two seconds after lock B is released.
    • Discuss
    • 8. What is the name of the method used to start a thread execution?

    • Options
    • A. init();
    • B. start();
    • C. run();
    • D. resume();
    • Discuss
    • 9. Which of the following will directly stop the execution of a Thread?

    • Options
    • A. wait()
    • B. notify()
    • C. notifyall()
    • D. exits synchronized code
    • Discuss
    • 10. Which of these will create and start this thread?
      public class MyRunnable implements Runnable 
      {
          public void run() 
          {
              // some code here
          }
      }
      

    • Options
    • A. new Runnable(MyRunnable).start();
    • B. new Thread(MyRunnable).run();
    • C. new Thread(new MyRunnable()).start();
    • D. new MyRunnable().start();
    • Discuss


    Comments

    There are no comments.

Enter a new Comment