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 trialDevon Parsons
7,766 Pointshow do you use inheritance in C#? Object Inheritance Code challenge?
namespace Treehouse.CodeChallenges { class Polygon { public readonly int NumSides;
public Polygon(int numSides)
{
NumSides = numSides;
}
}
class Square
{
public readonly int SideLength;
}
class Square : Polygon
} }
namespace Treehouse.CodeChallenges
{
class Polygon
{
public readonly int NumSides;
public Polygon(int numSides)
{
NumSides = numSides;
}
}
class Square
{
public readonly int SideLength;
}
class Square : Polygon
}
1 Answer
Steven Parker
231,198 PointsThere are a few steps involved in the challenge task.
- adding " : Polygon" was the right idea. But it needs to be added to the original class definition.
- you still need to make a constructor for your new class.
- your constructor will also have a colon and an explicit call to base (see example in video)
You might want to re-watch the video on Inheritance in Code. Be sure to watch how MapLocation is constructed to inherit from Point.