Здравствуйте, задачу я решила, но стало интересно, почему если static меняю на this, то переменная applesPrice перестает считать и выводит только входные значения?
public class Solution {
public static void main(String[] args) {
Apple apple = new Apple();
apple.addPrice(50);
Apple apple2 = new Apple();
apple2.addPrice(100);
}
public static class Apple {
int applesPrice = 0;
public void addPrice(int applesPrice) {
System.out.println("Стоимость яблок на входе " + this.applesPrice);
this.applesPrice = this.applesPrice + applesPrice;
System.out.println("Стоимость яблок сумма" + this.applesPrice);
}
}
}
То есть через статик понятно как работает, а как сделать, чтобы все работало через this?