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

Ryan Wood
Ryan Wood
888 Points

Trouble with adding a second parameter to the constructor.

The questions is this: Add a second parameter to the constructor named reactionTime after the existing parameter and use it to initialize the value of the ReactionTime field.

In the first question I constructed public readonly int ReactionTime; and in this questions I am attempting to add another parameter by doing this:

int reactionTime = ReactionTime;

Is this what is meant by adding another parameter or does this mean to add multiple parameters in a parenthesis after "public readonly int ReactionTime;

Trying to grasp what is meant here so any assistance would be greatly appreciated. I know this is probably simple but I want to be sure I have a firm understanding of what is being asked.

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

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


    }
}

1 Answer

Daniel Medina
Daniel Medina
13,863 Points

You have the right general idea about how to declare your ReactionTime field, but unfortunately, that is not how you add a parameter to your constructor.

You need to go to this part of your code...

public Frog(. . .)

And add this:

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

I understand that constructors can be tricky, so here are a few extra links for you:

https://www.tutorialspoint.com/csharp/csharp_classes.htm https://www.dotnetperls.com/constructor

Good luck with the rest of module!

Ryan Wood
Ryan Wood
888 Points

Daniel, I was so close but thank you! I get it now. I understand a little better now after browsing your links. Those links are clutch!