Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Harnessing the Power of Objects Methods and Constants

java-repl - removed the "final" part of the code. "IllegalAccesError" Why?

So out of curiosity, I removed the "final" from:

public final int MAX_PEZ = 12;

and attempted to load

"pd.MAX_PEZ = 45"

in java-repl. I received

"public int MAX_PEZ = 12;"

Why is that?

//EDIT: Nevermind. It seem that I forgot to use the "PezDispenser pd = new PezDispenser("Yoda");" command.

Guillem Garcia Sans
Guillem Garcia Sans
613 Points

I did the same thing to test the capabilities of the "final" keyword, and I got stuck at the same error. This is the sequence of commands I write on the repl console:

:load PezDispenser.java

PezDispenser pd = new PezDispenser("Java");

pd.MAX_PEZ = 2;

/* and then I get */

java.lang.IllegalAccessError.


What is going on?

ah, nvm, loaded again the object and got expected results.