I've just started learning Java and it's great. One thing I need to understand that in a class we can access instance variable in two ways:
class Box {
// Instance variables
private int width;
private int height;
private int depth;
// First way
public void set_volume(int a, int b, int c) {
this.width = a;
this.height = b;
this.depth = c;
}
// Second way
public void set_volume_v2(int a, int b, int c) {
width = a;
height = b;
depth = c;
}
}
Here, Instance variable is accessible without this
keyword and with it. So what's the best way? OR What's the difference between them?