A class, either directly inheriting object or indirectly inheriting object, as follows:
Class a{ } Class B extends a{ } |
B is a subclass of a, and a is a subclass of object, so B indirectly inherits object.
So, we can say this: All classes in Java inherit the object!
Further, it can be said that all classes, all have the method in the Object!
Here we learn the 4 methods of object, learn the method of object, it is equivalent to all the classes of these 4 methods are learned!
GetClass () method, as the name implies, GetClass is to get the name of the class to which an object belongs!
The ToString method is declared as follows:
Public String toString () {
....
}
As can be seen from this declaration, the return value type of the ToString method is string!
Output an object directly, and the return value of the ToString method that outputs the object is the same!
We can know that the output object and the output object's ToString return value is the same! But we also see that the content of the return value of the ToString method for different objects is different! For example, date ToString gets the time, and the string's ToString gets the contents of the strings, and the ToString of Test gets the address of the object in memory.
Why not the same kind of ToString method return content is not the same? Because ToString is a method of object, other classes directly or indirectly inherit object, and the system-built class overrides the ToString method of object.
Yi Yue (Shenzhen) technology Co., Ltd.
Make Happiness easier
: Ejoyyojoy
Weibo: Http://weibo.com/EJoyYOJOY
Official website: http://www.ejoytec.com/
Inherited object in Java