java只有值传递!

/**
 * @author 031202
 *
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
class ValHold {
 public int i = 10;
}

public class TestParameter {
 public void amethod() {
  ValHold v = new ValHold();
  another(v);
  System.out.println(v.i);
 }

 public void another(ValHold v) {
  v.i = 20;
  ValHold vh = new ValHold();
  v = vh;
  System.out.println(v.i);
 }

 public static void main(String[] argv) {
  TestParameter o = new TestParameter();
  o.amethod();
 }
}

answer:
10
20

你可能感兴趣的:(java基础)