There is a thing I do not understand well: when virtual method is called, the base method is called as well?
Because when I use public override WinForm OnPaint method, in its body base.OnPaint(e) is called. I do not understand it, I thought virtual methods overrides the original one. If it is not usually called, why it is called in this case? Thank you
No, it is not called, if you don't call it explicitly from the derived class.
when virtual method is called, the base method is called as well?
No.
Because when I use public override OnPaint(), in its body base.OnPaint(e) is called. I do not understand it, I thought virtual methods overrides the original one.
The developer chose to call base.OnPaint(e) and also do something else. In other words, the base implementation is something which you have at your hand in case it is useful to you - you can call it, and then do some additional specific work.
If the function body was only a call to the base, then it would be equivalent to not writing the overriding function at all.
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