/**
* @author cj
* 值传递和引用传递
* java中的值传递和引用传递java中的值传递和引用传递值传递:方法调用时,
* 实际参数把它的值传递给对应的形式参数,方法执行中形式参数值的改变不
* 影响实际参 数的值。方法调用时,实际参数的引用(地址,而不是参数的值)
* 被传递给方法中相对应的形式参数,在方法执行中,对形式参数的操作实际
* 上就是对实际参数的操作,方法执行中形式参数值的改变将会影响实际参数的值。
*/
public class ChangeValue {
private int c = 22;
public void setC(int c) {
this.c = c;
}
public void change(int a, int b, int c){
b = a;
c = b;
System.out.println("add方法中的b = "+b);
System.out.println("add方法中的c = "+c);
}
public void setValue(int b){
setC(33);
System.out.println("setValue方法中的c = "+c);
}
public static void main(String[] args){
int a = 100;
int b = 200;
ChangeValue test = new ChangeValue();
test.change(a, b, test.c);
System.out.println("main方法中的b = "+b);
System.out.println("main方法中的c = "+test.c);
test.setValue(b);
System.out.println("main方法中的c = "+test.c);
}
}