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 trialchristian rylander
4,609 PointsC#
Can someone help me with the C# Objects, Method Overloading task?
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
2 Answers
Justin Horner
Treehouse Guest TeacherHello Christian,
Step 2 of the challenge wants you add the ability to provide a reaction time at the time the object is created by passing it to the constructor. The constructor method is Frog.
The constructor already has a parameter for tongue length, so to add a new parameter and assign the value passed in to our public read-only field looks like this.
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int NewReadonlyField;
public Frog(int tongueLength, int newReadonlyField)
{
TongueLength = tongueLength;
NewReadonlyField = newReadonlyField;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
I hope this helps.
Steven Parker
231,248 PointsFor task 1, use the declaration of TongueLength as a sample.
Create another line like that but with the name the challenge says to use.
christian rylander
4,609 PointsI forgot to mention that it is the second task I need help with. Can you give me a hint of the second task?
christian rylander
4,609 Pointschristian rylander
4,609 PointsThanks!
Justin Horner
Treehouse Guest TeacherJustin Horner
Treehouse Guest TeacherYou're welcome!