| Author |
pass by value for static
|
eric lee
Ranch Hand
Joined: Nov 04, 2002
Posts: 86
|
|
since a is a static variable,why that answer is not 1? public class X{ private static int a; public static void main(String[] args){ modify(a); System.out.println(a); } public static void modify(int a){ a++; } }
|
 |
dragon ji
Ranch Hand
Joined: Oct 31, 2002
Posts: 110
|
|
a is a primitive type variable,and when it was invoked by method as a parameter,it passed by value,and in method modify,the variable a is a local variable,it only exist in the method scope. correct me ,pls.
|
scjp 1.4<br />challenge haven't limit!
|
 |
dragon ji
Ranch Hand
Joined: Oct 31, 2002
Posts: 110
|
|
I changed the method modify as follows: public static void modify() { a++; } then the output is 1,because a is a class variable.
|
 |
eric lee
Ranch Hand
Joined: Nov 04, 2002
Posts: 86
|
|
|
maybe your right,dragon
|
 |
 |
|
|
subject: pass by value for static
|
|
|