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

Jose Perez
Jose Perez
1,338 Points

Don’t understand the topic fullly

Why does it need to be a sub class of the Point class? Why not the Map class? I don’t quite understand why would we need to do use inheritance or this class if we are just checking if it in the map and we already have a map class?

Ashley Carpenter
Ashley Carpenter
13,393 Points

Could you give a bit more details please? Maybe add the code?

Thanks

4 Answers

Just in case someone is still viewing this post. I will try to help out the best that I can.

I believe the same as Radu. Here in this example, it is a bit bloated. They are just trying to show the possibilities of inheritance.

A better example might be if you were designing a video game that had a character class. The character class would have characteristics such as a name, or age, male or female. They would also have capabilities such as walking, exploring, talking, greeting. These would be in the Parent class or Super class.

Now let's say your character is a wizard. Your character would still inherit all the originals characteristics from the character class, and all of it's abilities, but you would make your wizard more specific by adding spells known, and the ability to cast spells at all. The same would be for a fighter class that would add the ability to fight and quaff beer. As well as explore.

I hope this has cleared things up. The map example is a little foggy but it's just to show what's out there and possible.

Bonnie Edens
Bonnie Edens
1,214 Points

Nice example Darin, thanks! :)

Anytime. I am glad I could help!

This is so helpful, thanks for phrasing it this way.

If you're listening, Treehouse: please consider revising this video!

Bonnie Edens
Bonnie Edens
1,214 Points

Same question here! Why would you need a subclass that does exactly the same?

Radu - Adrian Buha
PLUS
Radu - Adrian Buha
Courses Plus Student 5,535 Points

From my understanding, Jeremy uses these two classes to explain the principle of Inheritance. But when you write your own code, you are free to make it to your own specification. You can put all the code in single class. But that practice is a bit messy and it's hard to understand it after a while.

If you have a hard time understanding some of the tutorials, my advice is to start again from the beginning (or at least from the last tutorial that you properly understood) and take notes. You will be surprised how handy those notes will be in the future. To be honest, I also didn't understand everything in my first try. Therefore I started watching these series again and I took notes this time. It helped a lot.

To me, programming is like cooking, you have to practice a lot in order to master it.

Jose Perez
Jose Perez
1,338 Points

Yes you see they inherent the point class and made the maplocation class a subclass why do why need a subclass can we check the location of a point in the map class the same way?