Many books say that the Java supports the call to the call, similar to the Person & A reference calls in C , and recently programming a series of issues, which makes me have doubts, so I will list these methods one by one, let's come together Take a look at the call mode in Java: Look below: Class Person {Private String Name; // Name Private String Sex; // Gender Public Person (String X, String Y) {this.name = x; this.sex = Y;} public void setStatus (string x, string y) {this.name = x; this.sex = y;} public string toString () {return name sex;} // ----- Exchange normal object - ---- Public Static Void Changeref (Person Tmpx, Person TMPY) {// Exchange TMPX and TMPY Object Person swapRef = Tmpx; TMPX = TMPY; TMPY = swapRef; // system.out.println ("Exchange in method RESULTS: REFA = " TMPX.TOString ()); // system.out.println (" Results Exchange in Method: Refb = " TMPY.TOSTRING ());} // ----- Exchange array Object ----- Public Static Void ChangeArrayref (Person [] X, Person [] Y) {// Exchange array object Person swapArrayref = x [x.length-1]; x [x.ley-1] = y x.length-1]; y [x.length-1] = swapArrayref;} // ----- Exchange array ----- public Static void changeArray (int [] x, int [] y) {int [] TMP = x; x = y; y = tmp;}} public class demo {public static void main (string [] args) {// ------ Establish and construct two objects --------- Person Refa = New Person ("Zhang San"
, "Men"); Person Refb = New Person ("Li Si", "Men"); // Exchange the REFA object and the REFB object Person.ChangeRef (REFA, REFB); // As seen from the exchange result, actual object The SYSTEM.OUT.PRINTLN was not exchanged ("Results in the main function REFA =" refa.tostring ()); System.out.Println ("Results in the main function REFB =" refb.toString ))); // ------- Create two object arrays ---------- Person [] arraya = new person [1]; person [] arrayb = new person [1]; / / Structure Array Object Arraya [0] = New Person ("Wang 5", "Men"); Arrayb [0] = New Person ("Zhao Sa", "Men"); / * When the array object is NULL, it cannot Set its value, you must construct it first (that is, call the constructor), then set its value with other methods * / system.out.Println ('/ n' "array object exchange before exchange of arraya =" arraya [0] .tostring ()); system.out.println ("ARRAYB =" before "Array Object Exchange Arrayb [0] .tostring ()); // Exchange these two array objects Person.changeArrayref (Arraya, Arrayb); System.out.println ("- ARRAYA =" Arraya [0]. Tostring ()); system.out.println ("- ARRAYB =" arrayb [0] .tostring () ); // ------- Create two ordinary arrays -------- int [] a = New int [2]; int [] b = new int [2]; // assign a value for array of elements for (int i = 0; I A [0]); System.out.Println ("Array Exchange INTB [0] =" B [0]); // Exchange array Person.changeArray (A, B); System.Out.println ("- Switching results INTA [0] = " a [0]); system.out.println (" - The result of the exchange after INTB [0] = " b [0]);}} From the result of the program Look: When switching two objects, only the pointing point of the object handle, without changing the object content, so the method parameter is an object, does not exchange the actual content, but exchanged copy content. The array object is a bit strange, exchanged in the formal ginseng, and the actual parameters also reacted. As the array and normal data types, the changes in the metallin will not react into the inactive. The object is the same, the meticulum is changed, and the argument will not react. Summary: 1, the method can modify the status of the object parameters 2, the method does not allow the object parameter to point to the new object 3, the method cannot modify the basic type (int, byte, etc.) parameters