Inherited object in Java

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.