A, Object Overview
java.lang.Object class is the root class in the Java language, that is the parent of all classes.
In the object instantiation when the final look of the parent class is Object.
If a class is not specified parent class, then the default is inherited from the Object class.
Demo:
1 public class MyClass /*extends Object*/ {
2 // ...
3 }
Object class which contains methods 11, the following mainly describes two of them:
public String toString () `: Returns a string representation of the object.
public boolean equals (Object obj): indicate whether some other object with this object is "equal."
Two, toString method
method:
1 public class Person {
2 private String name;
3 private int age;
4
5 @Override
6 public String toString() {
7 return "Person{" + "name='" + name + '\'' + ", age=" + age + '}';
8 }
9
10 // 省略构造器与Getter Setter
11 }
Tips : When we use the direct output statements output object name, in fact, by the object calling its toString () method.