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

C# C# Objects Methods Method Overloading

What is the point of having 2 EatFly methods that do almost exactly the same thing?

In the exercise we have to create a new EatFly method and then just add a check for the reaction times. The exercise wont let you just add the reaction time check to the existing EatFly method.

I don't understand the point of the exercise.

2 Answers

Steven Parker
Steven Parker
231,269 Points

The whole point of the exercise is to demonstrate method overloading.

The concept of overloading is where you have more than one method with the same name but different signatures. The signature is the combination argument count, argument types, and return type.

So after completion of all tasks, you have two methods that are distinguished by the number of arguments they take. The fact that one does only part of the other might not make sense until you consider the scenario of upgrading an API while maintaining backwards compatibility.

So I could call the EatFly method with 1 or 2 arguments depending on the information I want to get back?

Steven Parker
Steven Parker
231,269 Points

They both return either true or false, based on the argument(s) given. But the method you call would determine whether or not the reaction time would be considered in determining the result.