C# C# Objects Inheritance Inheritance

abdur rafay
abdur rafay
1,933 Points

I dont understand why this is not correct.

I have done everything the question stated, I also tried to use preview but it does not seem to show any errors.

Polygon.cs
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;
        }
}

1 Answer

calp
calp
10,314 Points

Hello, I have identified the following with the code that you supplied, you are missing the closing brace for your Square class, and you are not passing 4 into the base constructor.

Here is the code with the two simple fixes,

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(4)
        {
            SideLength = sideLength;
        }
    }
}

As you can see, you were definitely on the right track!

abdur rafay
abdur rafay
1,933 Points

Oh thank-you so much, such a simple mistake on my part.