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 Helper Methods and Conditionals

why isEmpty() is true?

When you make a new PezDispenser in REPL, and then call the isEmpty() function, why does it return true?

We don't set the value of mPezCount when first constructing the dispenser, so that should have no value at all, right, not zero?

I don't see why

public boolean isEmpty(){ return mPezCount == 0; }

returns true. In life I can imagine it to be true, having no pez, but the above should have neither true or false as an answer

Is the field automatically set to zero when the dispenser is constructed?

1 Answer

Thank you, that explains things.