Value passing: (formal parameter type is the basic data type): When the method is called, the actual parameter passes its value to the corresponding formal parameter, the formal parameter only initializes its own storage unit content with the value of the actual parameter, it is two different storage units, so the change of the formal parameter value in the method execution does not affect the value of the actual parameter.
Reference passing: (formal parameter type is a reference data type parameter): Also known as a pass-through address. Method invocation, the actual parameter is an object (or an array), then the actual parameters and formal parameters point to the same address, in the execution of the method, the operation of the formal parameters is actually the operation of the actual parameters, the result is preserved after the end of the method, so the change in the method execution parameters will affect the actual parameters.
Packageedu.smc.xiao.test; Public classTest160107 { Public Static voidMain (string[] args) {A a=NewA (); Change (A.name,a.hello); System.out.print (A.name+ "SAY:"); for(inti = 0; i < a.hello.length; i++) {System.out.print (a.hello[i]); } System.out.println ("."); } Private Static voidChange (String name,Char[] Hello) {Name= "You"; hello[0] = ' W '; } }classa{String name= "Java"; Char[] Hello = {' H ', ' e ', ' l ', ' l ', ' O '}; }View Code
Value passing and reference passing