The object class is the parent class of all classes, and if a class is not explicitly identified with the extends keyword to inherit a class, then the class inherits the object class by default
The method of the object class is suitable for all subclasses
1.toString () method
The method returns the hash code (object address string) of the object, which is used to differentiate the object, which, like a social security number, distinguishes everyone
Man Man=new Mans ();
System,out.println (Man.tostring ());
Of course, the ToString () method is also overridden to represent the properties of the object
public void toString () {
Return "rewrite ToString method";
}
Equals () compares whether the object's reference is the same address
However, in general, if the two values of the object are the same, they need to be overridden when the parent class is not satisfied
Let's look at the first type:
public static void Main (string[] args) {
Dog Dog1=new Dog ();
Dog Dog2=new Dog ();
if (Dog1.equals (DOG2)) {
System.out.println ("Two objects are the same");
}else{
System.out.println ("Two objects are not the same");
}
}
The result must be different, because two objects open up different addresses, even if the property values of the two objects are the same.
2. To compare the values of two objects, you need to override the Equals method
The specific equals and = = relation refer to the following URL
Http://www.cnblogs.com/dolphin0520/p/3592500.html
Java-object class