Why do we use 'this' in setter method but not in getter method? [duplicate]
问题 This question already has answers here : What is the meaning of “this” in Java? (19 answers) Closed 2 years ago . For example, in the following code: private int id; public void setID(int ID) { this.id = ID; } public void getID() { return id; } Why don't we say return this.id in the getter function or conversely say id = ID in the setter function? Also is this actually necessary? I mean, aren't the functions called through an object, say obj.setid(1) or obj.getid() ? Will it work differently