0% found this document useful (0 votes)
4 views

Object Class

The Object class is the superclass of all Java classes, providing essential methods such as toString(), equals(), hashCode(), getClass(), clone(), finalize(), and thread management methods like wait(), notify(), and notifyAll(). These methods facilitate object representation, equality comparison, cloning, and garbage collection. Every Java class inherits from the Object class, directly or indirectly, ensuring a common structure and behavior across all objects.

Uploaded by

robin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Object Class

The Object class is the superclass of all Java classes, providing essential methods such as toString(), equals(), hashCode(), getClass(), clone(), finalize(), and thread management methods like wait(), notify(), and notifyAll(). These methods facilitate object representation, equality comparison, cloning, and garbage collection. Every Java class inherits from the Object class, directly or indirectly, ensuring a common structure and behavior across all objects.

Uploaded by

robin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OBJECT CLASS

The Object class is the superclass of all Java classes, located in


java.lang package. Every class in Java directly or indirectly inherits
from the Object class. If a class is extending any other class, then it
is derived indirectly from Object class, and if a class does not
extend any other class, then it is derived directly.
The toString() Method

If you want to represent any object as a string, toString() method comes into
existence. The toString() method returns the String representation of the
object.

Here’s how it is written in Object Class

public String toString() {


return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
The equals(Object obj) Method

Compares two objects for equality. Internally, it use hashcode method to


compare object.

Here’s how it is written in Object Class


public boolean equals(Object obj) {
return (this == obj);
}
The hashCode() Method

Java Object hashCode() is a native method and returns the integer hash code
value of the object.

The getClass() Method

The getClass() method is used to obtain the runtime class of an object. It


returns an instance of the Class class, which provides methods to inspect the
properties of the class, such as its name, superclass, interfaces, constructors,
methods, and fields.
The clone() Method
The object cloning is a way to create exact copy of an object. The
clone() method of Object class is used to clone an object.

The finalize() Method

The Java finalize() method of Object class is a method that the


Garbage Collector always calls just before the
deletion/destroying the object which is eligible for Garbage
Collection to perform clean-up activity.
The wait() / notify() / notifyAll() Methods
• wait(): Puts the thread in waiting state.
• notify(): Wakes up a single waiting thread.
• notifyAll(): Wakes up all waiting threads.

You might also like