asked 45.1k views
5 votes
Why are wait(), notify(), and notifyAll() methods defined in the Object class and not the Thread class?

1 Answer

1 vote

Final answer:

The wait(), notify(), and notifyAll() methods are defined in the Object class because they are used for inter-thread communication and synchronization, allowing threads to wait for conditions and be notified when they change.

Step-by-step explanation:

The wait(), notify(), and notifyAll() methods are defined in the Object class rather than the Thread class because they are used for inter-thread communication and synchronization.

These methods allow threads to wait for a condition to be met, and then be notified when that condition changes.

By defining these methods in the Object class, any object can be used as a monitor to control access to a shared resource, regardless of whether it is a Thread object or not.

answered
User JobJob
by
7.9k points