Functions of class inclusion in java

Source: Internet
Author: User

Functions of class inclusion in java

When writing a java program, we sometimes see this situation.

For example:

Class B {}

Class {}

New A (B) // in this statement, Class A contains Class B, meaning Class A can directly use Class B object class to call any data of Class B.

Here I give a metaphor to the human body.

For example, there is a human class person {}

There is a head class head {}

There is a body class body {}

There is a lower extremity class foot {}

Here we create a Head class

Head h = new head ();

One physical class

Body B = new body ();

One Lower Extremity

Foot f = new foot ();

Finally, create a human object.

Person p = new person (h, B, f );

In person, you can call any attributes of the header at will. In this way, you can divide this person into more details, you have to be more flexible.

I don't know if this is true or not!

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.