Home > Java > javaTutorial > body text

A classe Object

Mary-Kate Olsen
Release: 2024-09-21 14:18:05
Original
361 people have browsed it

A classe Object

Superclass of all classes:

  • Object is the implicit superclass of all classes in Java.
  • All classes inherit from Object, so a reference variable of type Object can reference any object or array.

Methods defined in the Object class:

  • The following are the main methods provided by the Object class:
  • Object clone(): Creates a new object identical to the original object.
  • boolean equals(Object object): Checks whether two objects are equal.
  • void finalize(): Called before an unused object is recycled (garbage collected).
  • Class getClass(): Returns the object's class at run time.
  • int hashCode(): Returns the hash code associated with the object.
  • void notify(): Resumes the execution of a thread that is waiting on the object.
  • void notifyAll(): Resumes the execution of all threads waiting on the object.
  • String toString(): Returns a string that describes the object.
  • void wait() / void wait(long milliseconds) / void wait(long milliseconds, int nanoseconds): Makes the object wait until another thread notifies.

Final methods:
The getClass(), notify(), notifyAll() and wait() methods are declared final and cannot be overridden.

Frequently overwritten methods:
equals(Object object): Compares two objects and returns true if they are equivalent.
toString(): Returns a textual description of the object. Automatically called when printing an object with println().

Use of generics in the getClass() method:

  • The return syntax of the getClass() method uses generic types, which allow the data type of a class or method to be parameterized.
  • The Object class offers a set of essential methods that can be used or overridden in any Java class, allowing the basic behavior of any object.

The above is the detailed content of A classe Object. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!