本帖最后由 王红霞 于 2012-7-10 15:54 编辑
为什么b是与不是全局变量对结果没有影响?当c是全局变量时对结果也没影响?
public class Demo
{
int a;
public void print_0()
{
a = 1;
int b = 2;
char c='n';
g(b,c);
System.out.println(a + ", " + b + ", " +c);
}
public void g(int b, char c)
{
a=5;
b=8;
c='v';
}
public static void main(String args[])
{
Demo d = new Demo();
d.print_0();
}
}
5, 2, n
======================================================================
public class Demo2
{
int a;
int b;
public void print_1() {
a = 1;
b = 2;
char c='n';
g(b, c);
System.out.println(a + ", " + b + ", " + c);
}
public void g(int b, char c) {
a = 5;
b = 8;
c='v';
}
public static void main(String args[]) {
Demo2 d = new Demo2();
d.print_1();
}
}
5, 2, n
|