The Object class is the root of the class hierarchy. The
Object class is the ancestor for all the classes in Java. That is,every class
in Java extends Objects, even though no extends are done with Object class
explicitly. All Objects, including arrays, implement the methods of this class.
Variable of type Objectcan be used to refer to objects of any type. A variable
of type Object is only useful as a generic holder for different values. But to
assign the Object class object to another other object type casting is needed.
Example
Object
obj = new Sample();
Sample
s = (Sample) obj;
No comments:
Post a Comment