Method parameter passing (reference type)

Method parameter passing (reference type)

//对基于引用类型(数组是引用类型)的参数,形式参数的改变,会影响实际参数的值
public class HelloWorld {
    
    
    public static void main(String[] args) {
    
    
        int arr[] = {
    
    10,20,30};//实际参数
        System.out.println("调用change方法前" + arr[1]);
        change(arr);
        System.out.println("调用change方法后" + arr[1]);
    }

    public static void change(int arr[]) {
    
    
        arr[1] = 200;//形式参数
    }
}

Guess you like

Origin blog.csdn.net/taoyingle/article/details/115205314