What methods does the Object class have?

Analysis & Answers


The Java Object class is the parent class of all classes, which means that all classes in Java inherit Object, and subclasses can use all methods of Object .

image.png

  1. registerNatives() //Private method
  2. getClass() //Return the running class of this Object.
  3. hashCode () //Used to get the hash value of the object.
  4. equals (Object obj) //Used to confirm whether two objects are "the same".
  5. clone() //Create and return a copy of this object.
  6. toString () //Returns the string representation of the object.
  7. notify() //Wake up a single thread waiting on this object monitor.
  8. notifyAll() //Wake up all threads waiting on this object monitor.
  9. wait(long timeout) //Causes the current thread to wait before other threads call the notify() method or notifyAll() method of this object, or the specified amount of time is exceeded.
  10. wait(long timeout, int nanos) //Cause the current thread to wait until other threads call the notify() method or notifyAll() method of this object, or some other thread interrupts the current thread, or a certain amount of actual time has passed. .
  11. wait() //Used to make the current thread lose its operation permission and the current thread enters the waiting sequence.
  12. finalize() //This method is called by the object's garbage collector when the garbage collector determines that there are no more references to the object.

Reflect & Expand


Object methods are available, but they are not necessarily easy to use. People often rewrite some methods to meet business needs.


Meow Interview Assistant: One-stop solution to interview questions. You can search the WeChat applet [Meow Interview Assistant] or follow [Meow Interview Assistant] -> Interview Assistant to answer questions for free. If you have any good interview knowledge or skills, I look forward to sharing them with you!

Guess you like

Origin blog.csdn.net/jjclove/article/details/124379418