Java parameter passing Method
If method A calls Method B and the parameter of Method B is of the basic data type, method A passes the parameter value to Method B. If the parameter of Method B is an object or an array, method A transmits A parameter reference to method B.
Example:
Public class VariableTest {
Public int membervariable = 0;
Public static void main (String [] args ){
Int param1 = 0;
VariableTest param2 = new VariableTest ();
VariableTest param3 = new VariableTest ();
Int [] param4 = {0 };
ChangeParameter (param1, param2, param3, param4 );
System. out. println ("param1 =" + param1 );
System. out. println ("param2.membervariable" + param2.membervariable );
System. out. println ("param3.membervariable" + param3.membervariable );
System. out. println ("param4 [0] =" + param4 [0]);
}
Public static void changeParameter (int param1, VariableTest param2, VariableTest param3, int [] param4 ){
Param1 = 1;
Param2.membervariable = 1;
Param3 = new VariableTest ();
Param3.membervariable = 1;
Param4 [0] = 1;
}
}
Print result:
Param1 = 0
Param2.membervariable1
Param3.membervariable0
Param4 [0] = 1