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 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!