The
Object class has the ToString method, and the Equals method
ToString () Overrides:
Equals () method:
Double equals comparison is, is the same object
equals, two objects are not like a
Package test;
public class Teacher {private String name;
private int age;
/** * Rewrite tostring */public String tostring () {return name;
}/** * Overrides equals * is used to determine if the current object is "as long as the given object" * compared to the content (property name) */public Boolean equals (object obj) {
if (obj = = null) {//passed in object is null return false;
} if (obj = = this) {//pass in the object whether it is itself return true;
The IF (obj instanceof Teacher) {//passed in object is the same type of Teacher t = (Teacher) obj;
Return T.name.equals (this.name) && t.age = = This.age;
} return false;
} public static void Main (string[] args) {Teacher tea = new Teacher ();
Tea.name = "Wang";
Tea.age = 31;
System.out.println (tea);//wang println () calls the ToString method Teacher tea1 = new Teacher ();
Tea1.name = "Wang";
Tea1.age = 31; System.out.println (tea==TEA1);//false double equals comparison is whether the same object System.out.println (Tea.equals (TEA1));//true}}