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 trialArturs Dubra
4,748 PointsGetters and setters, can't figure out the value I must set.
As far as I understand, I have to get and set the value to _numFliesEaten. I think that I got the value, but I have no clue how to set it!
It feels strange since in the video before challenge there was MapLocation field to which value could be assigned, but here there is no field to which I can assign any value.
namespace Treehouse.CodeChallenges
{
class Frog
{
private int _numFliesEaten;
public int GetNumFliesEaten()
{
return _numFliesEaten;
}
public void SetNumFliesEaten()
{
_numFliesEaten = ??;
}
}
}
2 Answers
Russell Kree
1,956 PointsRemember you will be setting the _numflieseaten variable from another class using the constructor. You cannot change the private variable so you must equal it to the value passed into the parameter.
namespace Treehouse.CodeChallenges { class Frog { private int _numFliesEaten;
public int GetNumFliesEaten()
{
return _numFliesEaten;
}
public void SetNumFliesEaten(int x)
{
_numFliesEaten = x;
}
}
}
Niek Beenen
1,066 PointsMohammad Hanbali int is the return type. A set will not return. So it will be a void.
Charlie Harcourt
8,046 PointsYes that was what I was doing wrong! Thanks
Arturs Dubra
4,748 PointsArturs Dubra
4,748 PointsThank you
Mohammad Hanbali
13,325 PointsMohammad Hanbali
13,325 PointsWhy is 'int' required for the getter but not the setter?