//关于两道错题
class Somthing{
public int addOne(final int x) {
//return ++x;//错误的,因为给x重新赋值了
return x+1;//正确的
}
}
public class Test {
public static void main(String[] args) {
Other o=new Other();
new Test().addOne(o);
}
public void addOne(final Other o) {
o.i++;//正确的,o不可以被修改,o中放的是地址,没有修改,o.i中放的是数,可以修改
}
}
class Other{
public int i;
}