A = 5 System. out. println ("first output:" + System. out. println ("third output:" + swap (a = 10 System. out. println ("second output:" +}
Third output: 5
Check that, although the value of a is changed in the swap method, the value of variable a in the main method remains unchanged. This verifies the above, if the basic data type is passed, the parameter value is changed in the method, but the actual parameter value cannot be changed...
Here I also want to explain that the String type does not belong to the basic data type, but it is not a reference data type. It is a special reference data type. Example:
String a = "Hello! "System. out. println ("first output:" + System. out. println ("third output:" + B = "Hello, Word" System. out. println ("second output:" +}
Result: Hello!
Second output: Hello, Word
Third output: Hello!
Why can't it be changed? Because the passing of a string is actually a value transfer, it cannot be changed ..........
[] A = {1, 2, 3 System. out. print ("result output before method call:" (I = 0; I <. length; I ++ System. out. print (a [I] + "" System. out. print ("\ n" System. out. print ("output result after the method is called:" (I = 0; I <. length; I ++ System. out. print (a [I] + "" swap (B [0] = 2 System. out. print ("output result after changing the value of parameter B:" (I = 0; I <B. length; I ++ System. out. print (B [I] + "" System. out. print ("\ n "}
Result output after changing the value of parameter B: 2 2 3
Result output after the method is called: 2 2 3
Check that the passed parameter is the value of the method parameter when the reference type is changed. The actual value will also be affected ............ if you still don't understand it, you can talk to me privately !!!