Object class in java

The Object class, in the java.lang package, is the topmost class in java bydefault. In other words, it is the root of all the class hierarchy.

You can use this class as reference of any child class whose type you don’t know. It will clear from the example given below. We have one method say ‘getInt’ which returns int type value. But suppose, you don’t know its return type, in that case you can use the Object class as reference.

Output : 2

Its methods and descriptions:

Methods Description
public boolean equals(Object obj) Indicates whether some other object is “equal to” this one
protected Object clone() throws CloneNotSupportedException Creates and returns a copy of this object.
protected void finalize() throws Throwable Called by the garbage collector to release the object which is unused
public final Class getClass() Returns the runtime class of an object.
public int hashCode() Returns a hash code value for the object.
public String toString() Returns a string representation of the object
public final void notify() wakes up single thread.
public final void notifyAll() wakes up all thread.
public final void wait() keep the current thread to wait, until another thread notifies (using notify() or notifyAll() method).
public final void wait(long timeout) Keeps the current thread to wait for the specified milliseconds, until another thread notifies (using notify() or notifyAll() method).
public final void wait(long timeout, int nanos) Keeps the current thread to wait for the specified miliseconds and nanoseconds, until another thread notifies (using notify() or notifyAll() method).
Print Friendly, PDF & Email
Main method in java
Access modifiers
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

1 Response

  1. August 4, 2015

    […] will not throw any error but a default constructor of Object class will be called. Every class extends Object class by default which is a parent class for all the […]

Leave a Reply

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