When an object is passed to a method, a copy of the object reference but not the object itself is made : Parameter « Java Source And Data Type « SCJP






import java.util.*;

class MainClass {
  public static void main(String args[]) {
    Vector v = new Vector();
    v.add(new String("a"));
    v.add(new String("b"));
    v.add(new String("c"));
    System.out.println(v);
    modifyReference(v);
    System.out.println(v);
    modifyReferencedObject(v);
    System.out.println(v);
  }

  static void modifyReference(Vector v) {
    v = new Vector();
    v.add(new String("1"));
    v.add(new String("2"));
    v.add(new String("3"));
  }

  static void modifyReferencedObject(Vector v) {
    v.removeAllElements();
    v.add(new String("1"));
    v.add(new String("2"));
    v.add(new String("3"));
  }
}








1.25.Parameter
1.25.1.A method's parameter list is a comma-separated list of parameter declarations.
1.25.2.A parameter may be declared as final so that it may be accessed from within a local inner class.
1.25.3.When a primitive value is passed to a method, a copy of the value is made
1.25.4.When an object is passed to a method, a copy of the object reference but not the object itself is made
1.25.5.When an value argument is passed into a method, changes to the argument value in the method do not affect the original.
1.25.6.Create a Reference to a Primitive
1.25.7.Changing the object reference in a method
1.25.8.Calling method operates on an object via the reference value
1.25.9.Passing Object Reference Variables
1.25.10.Passing Primitive Variables