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 Harnessing the Power of Objects Method Overloading

can someone explain this

public void fill(){ fill(MAX_PEZ); }

This method does not accept any parameter so how fill(MAX_PEZ)

2 Answers

There should be two "fill" methods. The one you talk about which does not take a parameter, and a second one which does take a parameter.

public void fill(int pezAmount) {
    pezCount += pezAmount;
}

The fill() method calls the fill(int pezAmount) method. They have the same name but are different. It's called method overloading.

I recommend you watch the video once more as it's a pretty important concept.

making default values! we connecting two methods, which are doing basically the same thing. But the buaty in it that if we do changes in fill (paremeters) we don't need to do any changes to fill()! one fill is for action, and the second is for math! I hope it helped! Never give up!