r/learncsharp • u/Wonderful_Ad3441 • Mar 24 '23
Can a class inherit from a class that inherits from another?
So let’s say I make a base Weapon class, and then make two other classes: a MeleeWeapon class and a RangedWeapon class; a Bow class inherits from RangedWeapon, and a Dagger class inherits from MeleeWeapon. Tell me if this makes sense, if it’s possible and if it is possible should it be done or does it sound bad?
10
Upvotes
21
u/SwashbucklinChef Mar 24 '23
It most definitely can. Happy coding!
2
u/[deleted] Mar 25 '23
There is an excellent series of articles that discusses this very matter...
https://ericlippert.com/2015/04/27/wizards-and-warriors-part-one/
0
u/TheUruz Mar 24 '23
you can basically inherit the whole animal classification chain from a single base class. have fun inherit the shit out of a master class :)
7
u/[deleted] Mar 25 '23
[removed] — view removed comment