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 trialMahmoud Khwaiter
8,870 PointsWhat's the difference between "TongueLength" and "tongueLength" in this code?
I've found a solution after a solid 15 minutes of trying different things but I'm still not 100% sure of the reasoning here
namespace Treehouse.CodeChallenges { class Frog { public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
bool eat = TongueLength >= distanceToFly;
return eat;
}
}
}
if we already established that TongueLength = tongueLength, so why does it matter which one of them I use?
1 Answer
Steven Parker
231,210 PointsOne is a passed-in argument, the other is an instance variable.
The constructor arguement tongueLength (little "t") only exists while the class instance is being constructed. But its value is copied into the instance variable TongueLength (big "T"), which persists for the life of the class instance.