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 trial

C# C# Objects Inheritance Inheritance

The Polygon class represents a 2 dimensional shape. It has a public field named NumSides. Create a new type of polygon c

Can anyone help me on this,

Polygon.cs
namespace Treehouse.CodeChallenges
{
    class Polygon
    {
        public readonly int NumSides;
        public Polygon(int numSides)
        {
            NumSides = numSides;
        }

    class Square : Polygon

         public Square(int numSides) : base(4)
        {

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

        }

    }

    }
}

2 Answers

Steven Parker
Steven Parker
231,269 Points

Here's a few hints:

  • the "Square" class seems to be inside the "Polygon" class (instead of after it)
  • the open brace to begin the class definition is missing
  • the constructor "Square" is defined twice
  • the definition with the correct argument and content is missing the explicit "Base" call
Ben Reynolds
Ben Reynolds
35,170 Points

Looks like you're missing a closing bracket for the polygon class and an opening bracket for the square class. Add those, and if I counted right, one of the closing brackets at the end would then need to be removed.