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

zachary wilborn
zachary wilborn
1,557 Points

Help figure out what i'm missing. looks right to me T_T

code compiles but its not right. cant figure out what i did wrong. feel like its something small though. please help me find it.

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;

        public Frog(int tongueLength,int reactionTime)
        {
            TongueLength = tongueLength;
            ReactionTime = reactionTime;

        }

        public bool EatFly(int distanceToFly, int flyReactionTime)
        {
            return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;

        }

    }
}

1 Answer

andren
andren
28,558 Points

The third task asks you to add another method called EatFly, it does not ask you to modify the existing EatFly method. Since the point of the challenge is to illustrate method overloading which is the act of having multiple methods with the same name, it defeats the purpose if you change the existing method.

If you leave the original method alone and add your new method below it like this:

namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;

        public Frog(int tongueLength,int reactionTime)
        {
            TongueLength = tongueLength;
            ReactionTime = reactionTime;

        }

        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }

        public bool EatFly(int distanceToFly, int flyReactionTime)
        {
            return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;
        }
    }
}

Then the code will be accepted.

zachary wilborn
zachary wilborn
1,557 Points

thanks so much. guess i was overthinking it . lol