Object - The Parent Class of All and Every Java Class
The object class in Java is
the parent class of all classes.
Everything is an object. Everything is derived from an object.
All classes automatically inherit the object class and methods that
are in it.
Methods that are in the Object class and that all other classes
automatically
inherit are:
boolean equals(Object obj)
//by default it check to see if two object share the same memory
address
//are they aliases of each other
//the String class, for example, overrides the normal behavior of
the equals //method and checks to see if the characters in both
strings are the same
String toString()
//by default the toString method is invoked when you ask
System.out.print or
//System.out.println to print out an object reference
//default behavior is to print out the memory address of the object
//to use make sure, your return a String, here is an example:
public String toString() {
String hold;
hold="hi there..";
return hold;
} |