One, the introduction

The Java Object class is the parent of all classes, which means that all Java classes inherit from Object, and subclasses can use all of Object’s methods. The Object class is in the java.lang package and is automatically imported at compile time. When we create a class that does not explicitly inherit from a parent class, it automatically inherits from Object and becomes a subclass of Object.

2, Object method details

Object contains: Object(), getClass(), hashCode(), equals(), Clone (), toString(), notify(), notifyAll(), Wait (long), wait(long,int), wait(), finaliz E () has twelve methods.

A brief description of the functionality of these methods:

1.object () : default constructor
public Object() { throw new RuntimeException("Stub!" ); }Copy the code
2. clone() : Creates and returns a copy of this object
@RecentlyNonNull protected Object clone() throws CloneNotSupportedException { throw new RuntimeException("Stub!" ); }Copy the code
3. Equals () : Indicates whether some other object is equal to this object
public boolean equals(@Nullable Object obj) { throw new RuntimeException("Stub!" ); }Copy the code
4.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
protected void finalize() throws Throwable { throw new RuntimeException("Stub!" ); }Copy the code
GetClass () : Returns the runtime class of an object
@NonNull public final Class<? > getClass() { throw new RuntimeException("Stub!" ); }Copy the code
6. HashCode () : Returns the hash value of this object
public int hashCode() { throw new RuntimeException("Stub!" ); }Copy the code
7. Notify () : Wakes up a single thread waiting on this object’s monitor
    public final native void notify();
Copy the code
NotifyAll () : Wakes up all threads waiting on the monitor of this object
    public final native void notifyAll();
Copy the code
ToString () : Returns a string representation of this object
@NonNull public String toString() { throw new RuntimeException("Stub!" ); }Copy the code
10. Wait () : Causes the current thread to wait until another thread calls notify() or notifyAll() of the object.
public final void wait() throws InterruptedException { throw new RuntimeException("Stub!" ); }Copy the code
11. Wait (long timeout) : Causes the current thread to wait for notify() or notifyAll() of the object.
public final void wait(long timeout) throws InterruptedException { throw new RuntimeException("Stub!" ); }Copy the code
12. Wait (long timeout, int nanos) : Causes the current thread to wait until another thread calls notify() or notifyAll(), or another thread interrupts the current thread, or a certain amount of time has elapsed
    public final native void wait(long var1, int var3) throws InterruptedException;
Copy the code