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);
}
}