Sobes.tech
Junior

What methods does the Object class provide in Java?

sobes.tech AI

Answer from AI

Here is a list of the main methods of the Object class:

  • clone(): Creates and returns a copy of the object.
  • equals(Object obj): Compares two objects for equality.
  • finalize(): Called by the garbage collector before the object is removed.
  • getClass(): Returns the Class object representing the class of this object.
  • hashCode(): Returns the hash code for the object.
  • notify(): Resumes a single thread that is waiting on this object's monitor.
  • notifyAll(): Resumes all threads waiting on this object's monitor.
  • toString(): Returns a string representation of the object.
  • wait(): Suspends the current thread until it is "woken up".
  • wait(long timeout): Suspends the current thread for a specified timeout.
  • wait(long timeout, int nanos): Suspends the current thread with a more precise timeout.