Friday, March 11, 2016

Object class in Java

Object class in Java


The Object class is the parent class of all the classes in java bydefault. In other words, it is the
topmost class of java.

The Object class is beneficial if you want to refer any object whose type you don't know.
Notice that parent class reference variable can refer the child class object, know as upcasting.

Let's take an example, there is getObject() method that returns an object but it can be
of any type like Employee,Student etc, we can use Object class reference to refer that

object. For example:

    Object obj=getObject();//we don't what object would be returned from this method 

The Object class provides some common behaviors to all the objects such as object can
be compared, object can be cloned, object can be notified etc.


No comments:

Post a Comment