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

I do not understand what I am trying to do.

I assume I have done the correct code but the program keeps saying I need a return even though I already have one?

Frog.cs
using System;
namespace Treehouse.CodeChallenges

{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;

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

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

    }
}

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

This is the full compile error that I'm getting:

Frog.cs(19,16): error CS1520: Class, struct, or interface method must have a return type
Compilation failed: 1 error(s), 0 warnings

So on line 19, it's expecting a return type.

public ReactionTime(int reactionTime)

Constructors are special in that they don't have a return type in the way that other methods do. But constructors need to have the same name as the class, in this case Frog, so it doesn't see this as a constructor.

I think you might have misread the instructions. It says "Add a second parameter to the constructor named reactionTime " not "add a second constructor*.

Let me know if you need more help.