Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,703 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.