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 in Code

Point x = new MapLocation?

How can a variable of type Point inherit a new MapLocation value and still function if the MapLocation can potentially have more information in it than the original Point class allows?

I understand that MapLocation is a sub class of point. But this still doesnt make sense to me. Its as if you are trying to set a more primitive class variable (such as int) to a more advanced class value (such as a double)

1 Answer

Steven Parker
Steven Parker
231,198 Points

This wouldn't apply to int's and double's, because they do not have an "is a..." relationship. Neither one is derived from the other.

But if you assign a MapLocation to Point variable (or pass it as an argument to a method expecting a Point), then only the parts of it that are inherited from Point will be available. Clearly, it would be a waste if the "MapLocation" parts are never used, but it's handy in cases when you do something (such as calling a method that uses a Point) and those parts aren't needed just for that operation.

Thank you for all of the questions you answer. You're a big help!