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

2 questions ?

Hello.

why we set mPezCount = 0 in the constructor and what mPezCount = MAX_PEZ mean?

can somebody explain it to me please?

.

2 Answers

Simon Coates
Simon Coates
28,694 Points

The constructor is meant to set an object up for use. This means putting it's values in an initial state. To begin with, the PezDispen As for "mPezCount = MAX_PEZ", this is assignment. The value on the right hand side (MAX_PEZ) is placed into the variable on the left hand side (mPezCount). The PezDispenser is empty to begin with, and then it is set to be full.

But why mPezCount = MAX_PEZ? i didn't really understand this

Simon Coates
Simon Coates
28,694 Points

it sets the internal value for current number of pez to be the maximum value that the dispense can hold (as defined by the MAX_PEZ constant). It occurs within the load method. You create the dispenser (at which point it contains no pez - hence the assignment of 0 in the constructor), and then you can fill it (this is what the load method does).

ohh got it thank you very much!