Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.