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

  1. Object

  2. Thread

  3. Runnable

  4. Class


Correct Option: A

AI Explanation

To answer this question, you need to understand the concept of multi-threading in Java. The wait(), notify(), and notifyAll() methods are used for inter-thread communication and are defined in the Object class.

Let's go through each option to understand why it is correct or incorrect:

Option A) Object - This option is correct because the wait(), notify(), and notifyAll() methods are defined in the Object class. Every class in Java is a subclass of the Object class, and therefore, these methods are available in all classes.

Option B) Thread - This option is incorrect because the Thread class is responsible for creating and managing threads, but it does not define the wait(), notify(), and notifyAll() methods.

Option C) Runnable - This option is incorrect because the Runnable interface is used to define a task that can be executed by a thread. It does not define the wait(), notify(), and notifyAll() methods.

Option D) Class - This option is incorrect because the Class class is used to represent classes and interfaces in Java. It does not define the wait(), notify(), and notifyAll() methods.

The correct answer is Option A) Object. This option is correct because the wait(), notify(), and notifyAll() methods are defined in the Object class.

Therefore, the correct answer is Option A) Object.

Find more quizzes: