内存练习 - 函数 与 对象Q37 E06
从 Main 的 run 方法 开始绘制内存
在每个检查点,检查你画的内存是否跟答案一致
练习 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public class Point { private int x; private int y; public Point() { } public Point(int x, int y) { this.x = x; this.y = y; } public void add(Point delta){ this.x += delta.x; this.y += delta.y; }}
1 2 3 4 5 6 7 8 public class Driver { public static void main(String[] args) { Point p1 = new Point(3, 4); Point p2 = new Point(1, 1); p1.add(p2); // 检查点 }}
检查点 答案

练习 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public class Point { private int x; private int y; public Point() { } public Point(int x, int y) { this.x = x; this.y = y; } public Point added(int dx, int dy) { return new Point(x + dx, y + dy); }}
1 2 3 4 5 6 7 public class Driver { public static void main(String[] args) { Point p1 = new Point(3, 4); Point p2 = p1.added(1, 1); // 检查点 }}
检查点 答案

练习 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public class Point { private int x; private int y; public Point() { } public Point(int x, int y) { this.x = x; this.y = y; } public Point added(Point point){ return new Point(x + point.x, y + point.y); }}
1 2 3 4 5 6 7 8 public class Driver { public static void main(String[] args) { Point p1 = new Point(3, 4); Point p2 = new Point(1, 1); Point p3 = p1.added(p2); // 检查点 }}
检查点 答案
