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# Intermediate C# Polymorphism Virtual Methods

Brooks G
Brooks G
5,284 Points

Could you also write "Health -= factor" in the Shielded Defender's version of DecreaseHealth?

Rather than call the base class's DecreaseHealth method with "base.DecreaseHealth(factor)," could you also simply write "Health -= factor," given Health is a public property that ShieldedInvader inherits?

I can see how calling the base's DecreaseHealth is also useful, especially if there's additional code that you want the overrided function in ShieldedInvader to also display without having to explicitly write it again (e.g. in mine -- and I think we added it at some point in a previous video -- I have a line of text that displays every time the DecreaseHealth method is called, informing the player that damage has been taken.)

1 Answer

Brooks G
Brooks G
5,284 Points

It seems as though he largely answered my question in the following sentence (I paused the video), lol. I think I have it right (more-so as it relates to the second paragraph of my question). If I'm misinterpreting, clarification would be much appreciated!