Reference Passing Test : Method Parameters « Class Definition « Java Tutorial






class Point {
  public int x;

  public int y;
}

public class MainClass {
  public static void increment(int x) {
    x++;
  }

  public static void reset(Point point) {
    point.x = 0;
    point.y = 0;
  }

  public static void main(String[] args) {
    int a = 9;
    increment(a);
    System.out.println(a); // prints 9
    Point p = new Point();
    p.x = 400;
    p.y = 600;
    reset(p);
    System.out.println(p.x); // prints 0
  }
}
9
0








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.