Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Coordinate { private int x; private int y; public Coordinate(int x,

ID: 3596561 • Letter: P

Question

public class Coordinate {
private int x;
private int y;
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
THE FOLLOWING 2 QUESTIONS REFER TO THE CODE FRAGMENT ABOVE
4. Based on the code above, the Coordinate Class is immutable:
(a) TRUE
(b) FALSE
Explain: ___________________________________________

5. Subclasses of Coordinate have access to the “x” iand “y” data member:
(a) TRUE
(b) FALSE
Explain: ___________________________________________

Explanation / Answer

4. (b) False

Immutable class means once it is created its contents cannot be changed. But this class contents will be changed if we try to change. Because we didn't initialise any final or constant variables in it.

5. (b) False

X and Y data members cannot be accessed to the subclasses because these data members are declared as private data members. Private data members cannot be accessed outside the class.