469,572 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

virtual and override methods question

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.
Nov 16 '05 #1
2 4360
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:ej**************@tk2msftngp13.phx.gbl...
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.

Nov 16 '05 #2
> 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! :>
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Raymond Lewallen | last post: by
10 posts views Thread by Martin Vorbrodt | last post: by
32 posts views Thread by Adrian Herscu | last post: by
4 posts views Thread by Rafael Veronezi | last post: by
14 posts views Thread by JPRoot | last post: by
15 posts views Thread by John Salerno | last post: by
5 posts views Thread by Marcel Hug | last post: by
reply views Thread by Peter Morris [Droopy eyes software] | last post: by
4 posts views Thread by David Zha0 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.