Quiz 5
Question 1
Briefly explain the difference between a class and an object.
Answer
A class is a template and an object is the thing created from that template.Question 2
Consider the following code.
public static void movePointA(Point p, int x, int y) {
p.x = x;
p.y = y;
}
public static void movePointB(int px, int py, int x, int y) {
px = x;
py = y;
}
Point coord = new Point(0, 0);
movePointA(coord, 1, 1);
movePointB(coord.x, coord.y, 7, 7);
A) Explain the difference between these two methods; in particular, their parameters.
Answer
movePointA() takes in a Point object as a parameter while movePointB() only takes in integers. Because objects are passed by reference, movePointA() actually changes the object passed in, while movePointB() does not because it passes in primitives.B) Draw a visual representation of what the object coord looks like after line 13.