public void setPosition(int amount) { this.position += amount; }
public class Fruits { private int position; public Fruits(int position) { this.position = position; } public void setPosition(int amount) { this.position += amount; } public int getPosition() { return position; } }
public class food { public static void main(String[] args) { Fruits apple = new Fruits(20); // Fix here: call setPosition on apple Object instead of Fruits class directly. apple.setPosition(6); System.out.println(apple.getPosition()); } }
Get Answers For Free
Most questions answered within 1 hours.