In theory, the Object class is the parent class of all class, that is, inherit the java.lang.object class directly or indirectly. Since all classes inherit in the Object class, the Extends Object keywords are omitted.
There are mainly the following methods in this class: Tostring (), GetClass (), Equals (), Clone (), Finalize (), where toString (), getClass (), equals are the most important methods.
Notice:
GetClass (), notify (), notify (), wait () and other methods are defined as the final type, so it cannot be rewritten.
getClass () method;
If you are not rewritten, if you want to call, you are generally used in combination with getName (), such as getclass (). Getname ();
Tostring () method;
Can be rewritten; if you provide a specific output mode for a specific object in actual use, when this type is converted into a string or a string connection, build an automatically call the rewrite Tostring () method.
Public objectinstance {public string tostring () {return "in"+getClass (). GetName ()+"rewriting the Tostring () method"} Public static void main (string arm []) {System m.out.println (New ObjectInstance ());}}Equals () method;
class v {} Public Class Overwriteequals {Public Static Void Main (String ARGS []) {string s1 = "123"; string s2 = "123"; ls (s2)); v1 = new v (); v2 = new v (); system.out.println (v1.equals (v2));}}Output results:
Run: True False Build Successful (Total Time: 0 Seconds)
It can be seen from this example that when using the EQUALS () method in a custom class for comparison, FALSE will be returned, because the default implementation of the EQUALS method is the "==" operator, that is, the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the reference address of the two objects, and the two objects, Not the content of the object. Therefore, in order to truly compare the content of the two objects, you need to rewrite the Equals () method in the custom class.