I am looking for some guidance on the this
keyword. I just learned about the concept and it is sort of confusing to me. Here is a piece of my code:
public class CashRegister {
private ArrayList<Double> items;
private int itemCount;
private double totalPrice;
public double getTotal() {
this.totalPrice = 0;
for (int i = 0; i < this.items.size(); i++) {
this.totalPrice = this.totalPrice + this.items.get(i);
}
return totalPrice;
}
}
My question is if am I using 'this' right? Should I use 'this' every time I use a variable like totalPrice
or the items
ArrayList?