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 trialblake littleton
14,255 PointsI'm not sure what I'm doing wrong
I thought I understood the getter and setter concept. I'm not sure what I'm doing wrong here.
namespace Treehouse.CodeChallenges
{
class Frog
{
private int _numFliesEaten;
private int _numFliesEaten;
}
public GetNumFliesEaten()
{
return _numFliesEaten;
}
public void SetNumFliesEaten(int value)
{
_numFliesEaten=value;
}
}
1 Answer
andren
28,558 PointsYou seem to grasp the basic concepts just fine, but there are three issues with your code:
You have added the getter and setter outside the body of the class, rather than inside where it belongs.
You have forgotten to add a return type to the
GetNumFliesEaten
getter method.You have also added the
_numFliesEaten
field twice. You should only define it once.
If you move the methods inside the body (within the {} brackets) of the class, add a return type to GetNumFliesEaten
, and remove the duplicate _numFliesEaten
field then your code will work fine.