473,287 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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 4497
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Raymond Lewallen | last post by:
I read this on this website page http://www.vbip.com/books/1861004915/chapter_4915_06.asp: Unlike many object-oriented languages, all methods in VB.NET are virtual. Now in BOL, Under...
10
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
4
by: Rafael Veronezi | last post by:
I have some questions about override in inheritance, and virtual members. I know that you can you override a method by two ways in C#, one, is overriding with the new keyword, like: public new...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
15
by: John Salerno | last post by:
Hi all. I have a question about virtual and override methods. Please forgive the elementary nature! First off, let me quote Programming in the Key of C#: "Any virtual method overridden with...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
0
by: Peter Morris [Droopy eyes software] | last post by:
I have solved this problem but it involved a static class, reflection, and a lot of code. I wanted to post it here because the solution using virtual class methods takes only a few lines of code....
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.