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 trialMason Austin
3,365 PointsHave I missed something?
According to the question I have done what it has asked right? I have initialised the variable NumSides and set it to 4, I have initialised the Square class with inheritance from the Polygon class. The SideLength variable was created in the Square class and is public and readonly. I don't know what I have done wrong here
namespace Treehouse.CodeChallenges
{
class Polygon
{
public readonly int NumSides;
public Polygon(int numSides)
{
NumSides = numSides;
}
}
class Square : Polygon
{
public readonly SideLength;
public Square(NumSides) : base(NumSides)
{
NumSides = 4;
SideLength = sidelength;
}
}
}
1 Answer
Steven Parker
231,198 PointsThere's a few issues:
- you need to declare the type (int) of "SideLength"
- the contructor's parameter name should be "sideLength" instead of "NumSides"
- the parameter also needs to have a type (int)
- "Numsides" will not be set directly, but by passing 4 to base ("
base(4)
") - the assignment has "sidelength" (lower case) instead of "sideLength" (with capital "L")