/** * Created by xabcd on 2019/2/16. */ public class java_change { int x = 0; }
/** * Created by xabcd on 2019/2/16. */ public class test_change { public static void main(String[] args) { java_change c = new java_change(); c.x = 20; fun(c);//调用fun方法,将c传递到方法之中 System.out.println("x = "+c.x); } public static void fun(java_change c1)//声明方法,接收类型为java_change类型 { c1.x = 25;//将c1中的x属性赋值为25 } } 结果 x = 25