473,400 Members | 2,145 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,400 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 4503
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.