virtual and override methods question

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
F

Flip

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! :>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top