1. Question: Which cannot directly cause a thread to stop executing?

    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.

    Note: Option C is correct. notify() - wakes up a single thread that is waiting on this object's monitor.
    1. Report
  2. Question: Which two of the following methods are defined in class Thread? start() wait() notify() run() terminate()

    A
    1 and 4

    B
    2 and 3

    C
    3 and 4

    D
    2 and 4

    Note: (1) and (4). Only start() and run() are defined by the Thread class. (2) and (3) are incorrect because they are methods of the Object class. (5) is incorrect because there's no such method in any thread-related class.
    1. Report
  3. Question: Which three guarantee that a thread will leave the running state? yield() wait() notify() notifyAll() sleep(1000) aLiveThread.join() Thread.killThread()

    A
    1, 2 and 4

    B
    2, 5 and 6

    C
    3, 4 and 7

    D
    4, 5 and 7

    Note: (2) is correct because wait() always causes the current thread to go into the object's wait pool. (5) is correct because sleep() will always pause the currently running thread for at least the duration specified in the sleep argument (unless an interrupted exception is thrown). (6) is correct because, assuming that the thread you're calling join() on is alive, the thread calling join() will immediately block until the thread you're calling join() on is no longer alive. (1) is wrong, but tempting. The yield() method is not guaranteed to cause a thread to leave the running state, although if there are runnable threads of the same priority as the currently running thread, then the current thread will probably leave the running state. (3) and (4) are incorrect because they don't cause the thread invoking them to leave the running state. (7) is wrong because there's no such method.
    1. Report
  4. Question: Which of the following will directly stop the execution of a Thread?

    A
    wait()

    B
    notify()

    C
    notifyall()

    D
    exits synchronized code

    Note: Option A is correct. wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. Option B is wrong. notify() - wakes up a single thread that is waiting on this object's monitor. Option C is wrong. notifyAll() - wakes up all threads that are waiting on this object's monitor. Option D is wrong. Typically, releasing a lock means the thread holding the lock (in other words, the thread currently in the synchronized method) exits the synchronized method. At that point, the lock is free until some other thread enters a synchronized method on that object. Does entering/exiting synchronized code mean that the thread execution stops? Not necessarily because the thread can still run code that is not synchronized. I think the word directly in the question gives us a clue. Exiting synchronized code does not directly stop the execution of a thread.
    1. Report
  5. Question: Which method must be defined by a class implementing the java.lang.Runnable interface?

    A
    void run()

    B
    public void run()

    C
    public void start()

    D
    void run(int priority)

    Note: Option B is correct because in an interface all methods are abstract by default therefore they must be overridden by the implementing class. The Runnable interface only contains 1 method, the void run() method therefore it must be implemented. Option A and D are incorrect because they are narrowing the access privileges i.e. package(default) access is narrower than public access. Option C is not method in the Runnable interface therefore it is incorrect.
    1. Report
  6. Question: Which will contain the body of the thread?

    A
    run();

    B
    start();

    C
    stop();

    D
    main();

    Note: Option A is Correct. The run() method to a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread. Option B is wrong. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread. Option C is wrong. The stop() method is deprecated. It forces the thread to stop executing. Option D is wrong. Is the main entry point for an application.
    1. Report
  7. Question: Which method registers a thread in a thread scheduler?

    A
    run();

    B
    construct();

    C
    start();

    D
    register();

    Note: Option C is correct. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread. Option A is wrong. The run() method of a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread. Option B is wrong. There is no construct() method in the Thread class. Option D is wrong. There is no register() method in the Thread class.
    1. Report
  8. Question: 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?

    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.

    Note: Option A. Either of the two events (notification or wait time expiration) will make the thread become a candidate for running again. Option B is incorrect because a waiting thread will not return to runnable when the lock is released, unless a notification occurs. Option C is incorrect because the thread will become a candidate immediately after notification, not two seconds afterwards. Option D is also incorrect because a thread will not come out of a waiting pool just because a lock has been released.
    1. Report
  9. Question: Which of the following will not directly cause a thread to stop?

    A
    notify()

    B
    wait()

    C
    InputStream access

    D
    sleep()

    Note: Option A is correct. notify() - wakes up a single thread that is waiting on this object's monitor. Option B is wrong. wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. Option C is wrong. Methods of the InputStream class block until input data is available, the end of the stream is detected, or an exception is thrown. Blocking means that a thread may stop until certain conditions are met. Option D is wrong. sleep() - Causes the currently executing thread to sleep (temporarily cease execution) for a specified number of milliseconds. The thread does not lose ownership of any monitors.
    1. Report
  10. Question: Which class or interface defines the wait(), notify(),and notifyAll() methods?

    A
    Object

    B
    Thread

    C
    Runnable

    D
    Class

    Note: 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.
    1. Report
Copyright © 2025. Powered by Intellect Software Ltd