/** Parameter passing of Method 1. Parameter: method declaration, argument arguments inside method parentheses: The value of the actual passed-in parameter when the method is called 2. Rule: Parameter passing mechanism in Java: value passing mechanism 1) formal parameters are basic data types: The value of the argument is passed to the parameter, In essence, a new piece of memory is opened in the stack memory, the copy of the argument is stored, the copy has the same value as the argument, and the operation on the copy does not affect the argument. The parameter is reclaimed by the JVM after the method ends, and the stack memory does not exist in the 2) parameter is the reference data type: The value of the reference type of the argument (the first address of the object entity of the corresponding heap space) is passed to the reference type variable of the formal parameter, but the address is passed to the*/classTestjava { Public Static voidMain (string[] args) {Testjava TT=NewTestjava ();//static methods cannot invoke non-static variables and methods, so the swap is invoked by instantiating the objectDataswap ds=NewDataswap (); System.out.println ("DS.I:" +ds.i+ "" + "DS.J:" +DS.J); Tt.swap (DS); System.out.println ("DS.I:" +ds.i+ "" + "DS.J:" +DS.J); System.out.println ("The value of the argument DS is:" +DS); } Public voidSwap (Dataswap d) {inttemp=D.I; D.I=D.J; D.J=temp; System.out.println ("The value of parameter D is:" +d);//same as the value of the argument DS }}classdataswap{inti=10; intJ=5;}
Parameter passing of the javase-method