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 trialyadin michaeli
Courses Plus Student 5,423 Points2 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
28,694 PointsThe 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.
yadin michaeli
Courses Plus Student 5,423 PointsBut why mPezCount = MAX_PEZ? i didn't really understand this
Simon Coates
28,694 Pointsit 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).
yadin michaeli
Courses Plus Student 5,423 Pointsohh got it thank you very much!
Derek Markman
16,291 PointsDerek Markman
16,291 Points.