ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

Object class in Java

The Object class is the parent/base class of all the classes in java by default.

An object class can be used in upcasting. If you don’t know the type of any object we can use Object class to refer that object.

Let’s take an example, there is getObject() method that returns an object but it can be of any type like Organisation , Branch, etc, we can use Object class reference to refer that object. For example:

  1. Object anyobject=getObject();//we don't know what object would be returned from this method

In Object class we have total nine methods which are mentioned below:

clone() – This method creates and returns a copy of the current object.
equals() – This method indicates whether some other object is “equal to” current one.
finalize() – This method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
getClass() – This method will return the runtime class of an object.
hashCode() – This method will return a hash code value for the object.
notify() – This method wakes up a single thread which is waiting on current object’s monitor.
notifyAll() – this method wakes up all threads that are waiting on current object’s monitor.
toString() – This method will return a string representation of the object.
wait() – This method will make current thread to wait until another thread invokes the notify() method or the notifyAll() method for the current object.

Facebook Comments

Check Your Domain Ranking

Leave a Reply

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

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!