virtual and override methods question

  • Thread starter Thread starter Flip
  • Start date Start date
F

Flip

In java, the default for methods is override. In c# that is not the case.
This talks about two classes, the base class and the overriding class. What
happens when you have a third class in the mix, extending the second class,
how can you indicate the method in the third class is overridding the
overridden method? Do you declare the second method to be virtual override?

ClassA
-------------
virtual DrawWindow(){//code}
^
|
|
ClassB
---------
override DrawWindow(){//code}

What happens if you want to creat a ClassC which extends ClassB, and you
want to override DrawWindow()? How do you declare the ClassB.DrawWindow
method?

Thanks.
 
Flip,

Override also implies virtual, so if you wanted to, in your class C, you
could do:

class C : B
{
override void DrawWindow()
{}
}

And the implementation of C will be called even when the reference is of
type A or B.

Basically, you just keep using override.

Hope this helps.
 
class C : B
I forgot the ":" extends in my example, thanks for catching that. :>
Basically, you just keep using override.
Hope this helps.
Oh, ok, yes it does help. Thank you! :>
 
Back
Top