Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
222,096 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!