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 if I don't use the this
keyword?