I figured it out after a while, but can someone explain why in this example "Apple.applePrice" works and "this.applePrice" doesn't? I'm sure it has to do with the difference in static and non-static but I don't understand it.
public class Solution {
public static void main(String[] args) {
Apple apple = new Apple();
apple.addPrice(50);
Apple apple2 = new Apple();
apple2.addPrice(100);
System.out.println("The cost of apples is " + Apple.applePrice);
}
public static class Apple {
public static int applePrice = 0;
public static void addPrice(int applePrice) {
Apple.applePrice += applePrice;
}
}
}