From CS160

Main: Lab7Solution

Part 1: Note that p is changed by mystery because it is passed by reference:

import java.awt.Point;

public class Lab7 {
	public static void main(String[] args) 
	{
	    Point p = new Point(2, 3);
	    mystery(p);
	    System.out.println(p);
	}

	public static void mystery(Point q) 
	{
	    q.translate(-1, -2);
	}
}

Part 2: Point p is not changed by mystery because only a copy is passed:

import java.awt.Point;

public class Lab7 {
	public static void main(String[] args) 
	{
	    Point p = new Point(2, 3);
	    Point q = new Point(p);
	    mystery(q);
	    System.out.println(p);
	}

	public static void mystery(Point q) 
	{
	    q.translate(-1, -2);
	}
}
Retrieved from http://www.cs.colostate.edu/~asa/courses/cs160/fall08/pmwiki/pmwiki.php/Lab7Solution
Page last modified on October 18, 2008, at 10:49 AM MST