先来看个例子,分析一下输出结果。
package com.jian8.basic;
import java.util.Arrays;
public class test {
public static void main(String[] args){
int i = 1;
String str = "hello";
Integer num = 200;
int[] arr = {1,2,3,4,5};
MyData my = new MyData();
change(i, str, num, arr, my);//实参列表
System.out.println("i= " + i);
System.out.println("str= " + str);
System.out.println("num= " + num);
System.out.println("arr= " + Arrays.toString(arr));
System.out.println("my.a= " + my.a);
}
public static void change(int j, String s, Integer n, int[] a, MyData m){//形参列表
j += 1;
s += "world";
n += 1;
a[0] += 1;
m.a += 1;
}
}
class MyData{
int a = 10;
}
//i= 1
//str= hello
//num= 200
//arr= [2, 2, 3, 4, 5]
//my.a= 11
关于Java中局部变量、实例变量和静态变量在方法区、栈内存、堆内存中的分配,可以参考下面的博客:
作者:leunging
链接:
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务