I know the definitions of virtual
and sealed
keywords, but if you don't use either of them with a method, can the method be overriden by default?
I am coming from vb.net background. It goes like this in vb.net (from MSDN):
If the Overridable or NotOverridable modifier is not specified, the default setting depends on whether the property or method overrides a base class property or method. If the property or method overrides a base class property or method, the default setting is Overridable; otherwise, it is NotOverridable.
I just want to know if that's also true in C#.
No it cannot. You need to explicitly mark a method as virtual to allow it to be overridden in derived classes.
What you can do however, is hide a method by using the new keyword. (MSDN Documentation)
The sealed keyword is used on both class definitions and methods. It disallows inheriting from a class or overriding of a method. By default, if you don't use this keyword, others will be able to inherit from your class. (MSDN Documentation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With