Passing objects to methods : Method Parameters « Class Definition « Java Tutorial






class Letter {
  char c;
}

public class MainClass {
  static void f(Letter y) {
    y.c = 'z';
  }

  public static void main(String[] args) {
    Letter x = new Letter();
    x.c = 'a';
    System.out.println("1: x.c: " + x.c);
    f(x);
    System.out.println("2: x.c: " + x.c);
  }
}
1: x.c: a
2: x.c: z








5.7.Method Parameters
5.7.1.By Value or By Reference
5.7.2.Reference Passing Test
5.7.3.Passing objects to methods
5.7.4.Use an array to pass a variable number of arguments to a method. This is the old-style approach to variable-length arguments.