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 trialShing wai Chan
1,255 PointsDoes your Square class derive from the Polygon class?
Inn class Square i pass as: Class Square: Polygon. Should work?
namespace Treehouse.CodeChallenges
{
class Polygon
{
public readonly int NumSides;
public Polygon(int numSides)
{
NumSides = numSides;
}
}
class Square: Polygon
{
public readonly int SideLength;
public Square(int sideLength) : base (NumSides)
{
SideLength = sideLength;
NumSides = 4;
}
}
}
2 Answers
Steven Parker
231,248 PointsThe challenge apparently wants to see a space on both sides of the colon that specifies the inheritance. It also does not seem to like spaces between a function name and the parentheses (as you have with base). Neither of these are actual syntax errors in the language. You might want to report these as bugs to Treehouse Support, it may even get you a "special Exterminator badge".
Also remember that the base constructor runs first, so you can't assign NumSides in your constructor and then pass it to base. You'll have to pass a 4 directly to base.
Jeremy McLain
Treehouse Guest TeacherYep! This is problem in the code challenge. I've fixed it.
Shing wai Chan
1,255 PointsShing wai Chan
1,255 PointsThank you :) it was some space problem between the codes, and yes the : base(4). noted :)