java object class

Java Object Class Tutorial

Java Object Class is basically the parent class of all classes. In other words, it is the topmost class of java. By Default, It extends to every class of java. Object class comes under the java.lang package.

Lang package has included by default. If any Java class does not extend any other class then it is a direct child class of Object and if extends other class then it is indirectly derived. Therefore we can easily use all the methods of Object class. Object class has many inbuilt methods that we can use to fulfill the requirement. Check other Java Turorial and examples.

Object Class Declaration

public class java.lang.Object

Class Constructors

Object class has only one constructor.


Object Class Methods

Java Object class has many inbuilt methods. These methods are very commonly used in programming. But we do not know exactly which method belongs to Object Class. There are list of all methods of Object Class. In this tutorial, we will explain each and every method with example.

1.) protected Object clone()

Parameters : Not Accept Any Parameter.
Return : Return the copy of this object.

2.) public boolean equals(Object oj)

Parameters : It accepts object which we want to compare.
Return : Return the boolean value true if given object matches otherwise it returns false.

3.) protected void finalize()

Garbage Collector calls this method. When garbage collection determines that there are no more references to the object. So this method automatically call and perform operation.

Parameters : No Parameters.
Return : NA.

4.) public final Class getClass()

Parameters : No Parameters.
Return : getClass() method returns the object of the class.

5.) String toString()

Java.lang.toString() method is very important and common used in Java. Because it converts any Object to String.

Parameters: NA
Return: This method will return the String representation of the Object.

6.) void notify()

Java.lang.Object.notify() method used in the Java Multithreading. But this method comes under the java.lang package. This method wakes up a single thread that is waiting on this object’s monitor. If many threads are waiting on this object, one of them is chosen to be awakened. So we can use this method.

Parameters: NA
Return: This method does not return anything. Because it has different functionality mentioned above.

We hope you like the post. If you have any doubt please comment below. So we can improve the content.

Leave a comment

Your email address will not be published. Required fields are marked *