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 trialmichael edmondson
4,512 PointsWhere am i going wrong with my code ? the challenge is not like prev ex in video
its feels like im close but it also feels like i may be mis reading the question
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 (int numSides)
{
SideLength = sideLength;
}
}
}
}
4 Answers
KRIS NIKOLAISEN
54,971 PointsFollow the error messages. The first one you receive is:
Did you define your Square class as an inner class of the Polygon class? Be sure to define the Square class before or after the definition for the Polygon class
You did. Just need to adjust some brackets so that Square is defined after Polygon.
The next error you receive is:
Does your Square constructor take a single parameter named sideLength
Check the case of sideLength. S should be lowercase.
The last error message you receive is:
Did you initialize the field 'numSides' to 4 in the base constructor?
You need to initialize numSides to 4
michael edmondson
4,512 PointsWhat Exactly is wrong with my brackets? it wasnt extactly went over like this in the videos they had seperate files for the classes
KRIS NIKOLAISEN
54,971 PointsBased on your brackets the Square class is inside the Polygon class. You have (some code omitted)
class Polygon
{
class Square : Polygon
{
}
}
It should be:
class Polygon
{
}
class Square : Polygon
{
}
michael edmondson
4,512 Pointsnamespace 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 = 4)
{
}
}
}
how is then done is the base constructor initialize numSides to 4 this was never went over in the video