What is the point of getters and setters? [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why use getters and setters? I have read books on Java , saying that it is good to create setters and getters for variables such as x and y . For example: public int getX(){ return x; } public void setX(int x){ this.x = x; } But what is the difference from that and ...(shape.x)... // basically getX() and shape.x = 90; // basically setX() If setters and getters are better, could you explain to me what practical