挺有意思的一道Java题
程序员文章站
2024-03-12 22:51:03
...
输出答案: 15 0
20
package LianXi;
class Value {
int i = 15;
}
public class Test {
public static void main(String argv[]) {
Test t = new Test();
t.firstMethod();
}
public void firstMethod() {
int i = 5;
Value v = new Value();
v.i = 25;
secondMethod(v, i);//15 0
System.out.println(v.i);//20
}
public void secondMethod(Value v, int i) {
i = 0;
v.i = 20;//20
Value val = new Value();
v = val;
System.out.println(v.i + " " + i);
}
}