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

Shing wai Chan
Shing wai Chan
1,255 Points

Does your Square class derive from the Polygon class?

Inn class Square i pass as: Class Square: Polygon. Should work?

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;

      }

    }
}

2 Answers

Steven Parker
Steven Parker
231,271 Points

The challenge apparently wants to see a space on both sides of the colon that specifies the inheritance. It also does not seem to like spaces between a function name and the parentheses (as you have with base). Neither of these are actual syntax errors in the language. You might want to report these as bugs to Treehouse Support, it may even get you a "special Exterminator badge".

Also remember that the base constructor runs first, so you can't assign NumSides in your constructor and then pass it to base. You'll have to pass a 4 directly to base.

Shing wai Chan
Shing wai Chan
1,255 Points

Thank you :) it was some space problem between the codes, and yes the : base(4). noted :)

Jeremy McLain
STAFF
Jeremy McLain
Treehouse Guest Teacher

Yep! This is problem in the code challenge. I've fixed it.