C# C# Objects Inheritance Inheritance

Mohammed Almahruqi
Mohammed Almahruqi
751 Points

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

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

    public Polygon(int numSides)
    {
        NumSides = numSides;
    }
}

}

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

        public Polygon(int numSides)
        {
            NumSides = numSides;
        }
    }
}

1 Answer

Erik Gabor
Erik Gabor
4,251 Points

In the challenge you have to create a new subclass of the Polygons: the Square calling the parent by the base constructor setting by default NumSides to 4

    class Square : Polygon 
    {
        public readonly int SideLength;
        public Square( int sideLength) :    base(4) 
        {
            SideLength = sideLength;
        }
    }