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

Mahvish Irfan
Mahvish Irfan
449 Points

Why did we make the mCharacterName private but the MAX_PEZ public?

I don't get it

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Mahvish,

do you need more help?

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Mahvish,

sorry for delay :}

mCharacterName is a private variable. It should be accessable only from the class itself and not from ouside. This is a kind of variable protection from beeing changed or broken accidently or intentionally.

Therefor yor create a getter and seeter method to be able to get and set the state of mCharacterName. This is a common practise called ENCAPSULATION. Here a link for more information:

http://beginnersbook.com/2013/05/encapsulation-in-java/

The reason MAX_PEZ is public is that everyone should know how many PEZ can be inside a dispenser. The MAX_PEZ is a constant variable (uppercased) and it is marked as final, so it canΒ΄t be changed !!!

So everyone knows that our dispenser holds 8 Pez and canΒ΄t change this number, because it is final (protected from beeing changed)

Makes sense?

G