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 Method Signatures

Adam Brown
Adam Brown
1,893 Points

MAX_PEZ

When this happens, public void load() {load(MAX_PEZ);}, won't it be adding 12 pez to however many pez are already in there, going over the maximum amount then?

3 Answers

Christopher Augg
Christopher Augg
21,223 Points

Hello Adam,

I believe you are referring to the lesson on overloading the load method where Craig has:

      public void load() {
         load(Max_Pez);
     }

     public void load(int pezAmount) {
         mPezCount += pezAmount;
     }

Nice eye! You are correct. There is a an oversight here in regards to overfilling mPezCount. However, Craig did this intentionally to introduce new developers to this kind of mistake and introduce Exceptions. You can see this by watching his video on method signatures again at 3:42 as well as his next video, Exceptions.

I hope this helps.

Regards,

Chris

Nico Julian
Nico Julian
23,657 Points

Hi there,

To prevent it from going over the limit of 12, the method is defined like so-

public void load() { mPezCount = MAX_PEZ; }

This way, the load method will take however many are currently loaded (mPezCount) and set it to the limit (MAX_PEZ). No addition is taking place, so it can't go over this way.

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Christopher is correct, Craig does show you how to fix this in the next video, so continue on and fix that bug!