Is Java passing by reference or by value?

First need to understand the meaning of value passing and reference passing

Value transfer: when the method is called, the actual parameter is to assign a copy of itself to the formal parameter. Within the method, the modification of the parameter value does not affect the original actual parameter;

Reference transfer: when the method is called, the actual parameter transfers its own address to the formal parameter. At this time, the change of the parameter value in the method is the actual operation of the actual parameter;

If there is a program below.

int a=10;

getNumber(a);

public void getNumber(int a){

......

}

No matter how it is executed in the method body, the variable a of type int is always 10; and the parameter passed to the getNumber () method is just a copy object of the variable a.

Guess you like

Origin www.cnblogs.com/Vinlen/p/12717444.html