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

confuse of load(MAX_PEZ)

what does this do?

steve should i get your contact like on skype or should i just ask questions through treehouse? because you're really my go to guy when i'm confuse abt something

I'm on Skype - big.dog.consultants - or Twitter as OnlySteveH or on here. :-)

okay thanks

2 Answers

I carried on watching the videos so understand where you're coming from on this one! This is about overriding methods.

You originally have a method that sets the mPezCount member variable to the value stored in the constant MAX_PEZ. That makes sense, right?

Then, we're creating a new method that takes a number of items to add to the mPezCount rather than just adding 12, or whatever. So, you have a new method that takes a parameter and add the value of that parameter to the number contained in mPezCount. Make sense still? It just lets us add 1, or 2, or whatever rather than just MAX_PEZ.

Having two methods called the same thing is fine as they both have different signatures, i.e. their first line is different - one takes a parameter, one does not.

Here, we can build some efficiency, though. You'll have heard of DRY coding (Don't Repeat Yourself) - well, here, we are repeating ourselves a little. Rather than having the first (non-parameter) function change the value of mPezCount we can use the new function to do that for us. Inside of the old function, we call the new function, passing in MAX-PEZ as the parameter. The new function then receives this and adds MAX_PEZ to the value contained in mPezCount.

That's just a little bit slicker and means that only one load() method changes the value in mPezCount.

OK with that?

Steve.

P.S. I still have no idea what a Pez Dispenser is or what Pez's are!?

A pez is a candy, and a pez dispenser is a candy dispenser. This program is a simulating on how a real pex dispenser works. such as being dispense, refill and also have a character name of the dispenser

Ah, I see - thank you! :-)

Thanks Craig Dennis ! :-)

hello craig i was just wondering if there will be a C course and also when will the java fx course comeout

Thanks steve!, i did not notice that it just came out

Yep - just the other day. It's on my list to get on with! :-)

P.S. Did you get your head around the load(MAX_PEZ) thing in this thread?

yes i understand now. So now i know load(MAX_PEZ) on the first method means changing the parameter of the second method to MAX_PEZ so the numberOfPez + MAX_PEZ. thanks alot steve!

Cool - just checking it made sense. :-)