String类型变量虽然是引用型,但是传递参数时,是按基本类型的值传递,跟其他引用型的参数传递不一样,
- public class Test {
- public static void main(String[] args){
- int a = 10;
- int b = 20;
- change(a,b);
- System.out.println(a);
- System.out.println(b);
- }
- public static change(int a,int b){
-
- int temp;
- temp = a;
- a=b;
- b=temp;
- }
- }
复制代码
|