What's the problem?
package com.codegym.task.task04.task0402;
/*
Price of apples
*/
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);
System.out.println("The cost of apples is " + Apple.apple2Price);
}
public static class Apple {
public static int applePrice = 0;
public void addPrice(int applePrice) {
this.applePrice = this.applePrice + 50;
}
}
}
this.applePrice A static variable is common to all the instances (or objects) of the class because it is a class level variable. try increment using class.variable addon: variable = variable + 50; short variant variable += 50;