Java Java Objects Harnessing the Power of Objects Filling the Dispenser

James Stride
PRO
James Stride
Pro Student 621 Points

not-static variable MAX_PEZ cannot be referenced from a static context PezDispenser.MAX_PEZ);

Cant figure out why Im getting this error since its exactly like Craigs code.
Example.java:7:error: non-static variable MAX_PEZ cannot be referenced from a static context PezDispenser.MAX_PEZ); ^

Madhuri Charugundla
Madhuri Charugundla
2,383 Points

You forgot to mention the keyword static before the constant variable MAX_PEZ. If you want the constant to be accessed from the class instead of object scope, then you have to mention static keyword. public static final int MAX_PEZ = 12;

2 Answers

James Stride
PRO
James Stride
Pro Student 621 Points

Thank you so much Madhuri ! I laughed about it once I saw that mistake.

Uris Nicolas
Uris Nicolas
1,906 Points

Thank you very much !!