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