0

Java Thread Quiz

Description: Java Thread Quiz
Number of Questions: 8
Created by:
Tags: java
Attempted 0/8 Correct 0 Score 0

What is the name of the method used to start a thread execution?

  1. init();

  2. start();

  3. run();

  4. resume();


Correct Option: B
Explanation:

The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Which cannot directly cause a thread to stop executing?

  1. Calling the SetPriority() method on a Thread object.

  2. Calling the wait() method on an object.

  3. Calling notify() method on an object.

  4. Calling read() method on an InputStream object.


Correct Option: C
Explanation:

notify() - wakes up a single thread that is waiting on this object's monitor.

Which of the following will directly stop the execution of a Thread?

  1. wait()

  2. notify()

  3. notifyall()

  4. exits synchronized code


Correct Option: A

Which method must be defined by a class implementing the java.lang.Runnable interface?

  1. void run()

  2. public void run()

  3. public void start()

  4. void run(int priority)


Correct Option: B

Which will contain the body of the thread?

  1. run();

  2. start();

  3. stop();

  4. main();


Correct Option: A

Which method registers a thread in a thread scheduler?

  1. run();

  2. construct();

  3. start();

  4. register();


Correct Option: C

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

  1. notify()

  2. wait()

  3. InputStream access

  4. sleep()


Correct Option: A

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

  1. Object

  2. Thread

  3. Runnable

  4. Class


Correct Option: A
- Hide questions