Data passing between classes in Java

Source: Internet
Author: User

Although the first time to learn Java, you know the Java class data transfer, may also understand, but may forget,

Exactly, this is used, and then only one data is transmitted to the last two classes consecutively.

method, either through a constructor, or through a set method.

constructor function:

The code is not good to demonstrate

1, class a,b,c, purpose, the data in class A to the class C

2. Now create an instance of Class A (as a handle) in B, and then "assign" it in the constructor of B (not initialize), the constructor should have class A as the argument, try to write the assignment statement to the first line.

3, when Class B is to be used in Class A, it is natural to pass a parameter to construct, at this time passing "this" as a parameter, it is equivalent to the B in the instance of a is assigned value,

4, because C to be used in B, the same method, the value is passed from B to C.

5, pass the value, or assign a handle, try to write to the front, to ensure that the subsequent statement calls its value will not be null

6, the finished.


Data passing between classes in Java

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.