Parameter Passing Mechanisms
An Introduction with Examples in Java |
Prof. David Bernstein |
Computer Science Department |
bernstdh@jmu.edu |
public class Pair { public int a, b; }
/** This function will swap the values of * the instance variables a and b in the object p */ public static void swapAttributes(Pair p) { int temp; temp = p.a; p.a = p.b; p.b = temp; }
public class Pair { public int a, b; }
/** This method will only swap the local copies * of the references to m and n */ public static void swapNotObject(Pair m, Pair n) { Pair temp; temp = m; m = n; n = temp; }