1, toString () is to rewrite, for the general object will have this method, in fact, the purpose of this method is to output the object in a string way: for example, a people class, there are name,age these two attributes, if you people p = New people ();
P.tostring ();
In so doing, the default output is a memory address.
Then you will think of rewriting ToString (), and this method, in its own way to output.
For example, the method of ToString modified to: return p.name+p.age;
The thing that ToString outputs at this time is the name and age of the class people.
ToString () is the Oject method, so you can override this method as long as the classes that inherit from Oject are wide. Application examples Edittext.gettext (). ToString ()
2, the rewrite refers to the parent class after inheriting, the subclass of a method of a specific implementation of the modification, can not modify its method name, when the System.out.println (object), the default use of ToString () method, the object to the string output, ToString () Method inherits the implicit base class of all classes (the Cellular object class of all classes), if a class does not override the ToString () method, then calling ToString () will get a string such as the class name + address name, and the other method name should not be wrong, whether you have added an override tag, Changing to a method name cannot be called an "override."
3, in writing Java code, in the background to print the value of variables to the console, when you print an object, is actually called the object's ToString () method. This is in the definition phase of the class, the property has not yet initialized, is the printing object, printing default is the object. toString (); Can be understood as outputting all the attribute values;
4, General out.println (object) and System.out.println (object), where the output is the Object.ToString () method. Rewrite the ToString () method to output the text information you want
Note: Print an object, you can directly System.out.println (p), in fact, the Println method automatically calls the ToString () method.