Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Inheritance Inheritance

Where do I put the new class?

No matter where I put "class Square : Polygon", it keep telling me the same thing error message: "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. It seems like ive tried every spot posible and have no idea how this is supposed to be answered. When this was done in the video the person made a whole other document and that is not posible to do here.

Polygon.cs
namespace Treehouse.CodeChallenges
{
    class Polygon
    {
        public readonly int NumSides;

        public Polygon(int numSides) : base(4)
        {
            NumSides = numSides;
        }
    }

    class Square : Polygon
    {
        public readonly int SideLength;

        public Square(int sideLength) 
        {
            SideLength = sideLength;
        }
    }
}

1 Answer

The Square class is in the correct place, but you modified the Polygon class to default to having four sides rather than the Square class.

Try changing public Polygon(int numSides) : base(4) and public Square(int sideLength) to public Polygon(int numSides) and public Square(int sideLength) : base(4).

thank you so much it worked!! i kept getting an error message telling me the mistake was me placing the Square class in the incorrect place and didnt mention anything about the base placement.