Java – Object Class

Java – Object Class 2017-08-09T12:02:05+00:00

The Object class:

There is one special class, Object, defined by Java. All other classes are sub classes of Object.

That is, Object is a super class of all other classes.

This means that a reference variable of type Object can refer to an object of any other class.

Every class in java is descended from the java.lang.Object  class.

If no inheritance is specified when a class is defined, the super class of the class is Object by default.

EX :

public class circle { … }

is equivalent to

public class circle extends Object { … }

Methods of Object class

The methods getclass(), notify(), notifyall() and wait() are declared as final.

You may override the others.

tostring()

public String tostring()

it returns a String that describe an object.

It consisting class name, an at (@) sign and object memory address in hexadecimal.

EX :

Circle c1 = new Circle();

System.out.println(c1.tostring());

It will give O/P like Circle@15037e5

We can also write System.out.println(c1);

Prev Next