![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
package com.java.test;
publicclass T1 {
publicstaticvoid main(String args[]){
String s1="123";
int t2=333;
T1 t=new T1();
t.t1(s1);
System.out.println(s1);
t.t3(t2);
System.out.println(String.valueOf(t2));
t.t4(s1);
System.out.println(s1);
t.t5(t2);
System.out.println(String.valueOf(t2));
}
publicvoid t1(String s1){
s1="haha";
}
publicvoid t3(int t2){
t2=6666;
}
public String t4(String s1){
s1="haha";
return s1;
}
publicint t5(int t2){
t2=6666;
return t2;
}
}
publicclass T1 {
publicstaticvoid main(String args[]){
String s1="123";
int t2=333;
T1 t=new T1();
t.t1(s1);
System.out.println(s1);
t.t3(t2);
System.out.println(String.valueOf(t2));
t.t4(s1);
System.out.println(s1);
t.t5(t2);
System.out.println(String.valueOf(t2));
}
publicvoid t1(String s1){
s1="haha";
}
publicvoid t3(int t2){
t2=6666;
}
public String t4(String s1){
s1="haha";
return s1;
}
publicint t5(int t2){
t2=6666;
return t2;
}
}
运行结果:
123
333
123
333
加断点,调试,就可以看到一步一步的运行过程了。得到结果了。
没有变成haha,6666
通过调试,可以知道,参数只在自己的方法里面起作用。