Theoretically the object class is the parent class of all classes, that is, directly or indirectly inheriting the Java.lang.Object class. Because all classes inherit from the object class, the extends object keyword is omitted.
The main methods in this class are ToString (), GetClass (), Equals (), Clone (), Finalize (), where ToString (), GetClass (), Equals is the most important method.
Attention:
GetClass (), notify (), Notifyall (), wait (), and so on are defined as final types and cannot be overridden in the object class.
GetClass () method;
Can not be rewritten, to invoke words, General and getName () are used jointly, such as GetClass (). GetName ();
ToString () method;
Can be overridden, if a specific output pattern is provided for a particular object in actual use, the overridden ToString () method is built automatically when the type is converted to a string or string connection.
Public objectinstance{public
String toString () {return
"in" +getclass (). GetName () + override ToString () method
} Public
static void Main (String arg[]) {
System.out.println (new ObjectInstance ());
}
Equals () method;
Class V {
} public
class overwriteequals{public
static void main (string args[]) {
string s1= "123";
String s2= "123";
System.out.println (s1.equals (S2));
V v1= New V ();
V v2= New V ();
System.out.println (V1.equals (v2));
}
Output results:
As you can see from this example, when you compare using the Equals () method in a custom class, you return false because the default implementation of the Equals method is the "= =" operator, which compares the reference addresses of two objects rather than the contents of the objects. So to really compare the contents of two objects, you need to override the Equals () method in your custom class.