469,645 Members | 1,971 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

how can i prevent overriding/hiding a base class method

Hi,

how can i prevent from a derive class to override/hide a base class method ?
because in c# there is the new keyword on a method.
i am looking for the same functionality as the 'final' keyword in java.

Thanks.
Nov 17 '05 #1
4 14635
yaron wrote:
Hi,

how can i prevent from a derive class to override/hide a base class method ?
because in c# there is the new keyword on a method.
i am looking for the same functionality as the 'final' keyword in java.

Thanks.


Use the Sealed Keyword.

--
Rob Schieber
Nov 17 '05 #2
If you do not mark a method as "virtual," it can not be overridden by an
inherited class. However, the inherited class may re-define the method by
using the "new" keyword. Unfortunately, this is not something that can be
overcome with C#. You may find the following reference useful:

http://www.25hoursaday.com/CsharpVsJ...l#virtualfinal

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Hi,

how can i prevent from a derive class to override/hide a base class method
?
because in c# there is the new keyword on a method.
i am looking for the same functionality as the 'final' keyword in java.

Thanks.

Nov 17 '05 #3
Thank you all.

"Kevin Spencer" wrote:
If you do not mark a method as "virtual," it can not be overridden by an
inherited class. However, the inherited class may re-define the method by
using the "new" keyword. Unfortunately, this is not something that can be
overcome with C#. You may find the following reference useful:

http://www.25hoursaday.com/CsharpVsJ...l#virtualfinal

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
Hi,

how can i prevent from a derive class to override/hide a base class method
?
because in c# there is the new keyword on a method.
i am looking for the same functionality as the 'final' keyword in java.

Thanks.


Nov 17 '05 #4
"Rob Schieber" <sc******@hotmail.com> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
yaron wrote:
Hi,

how can i prevent from a derive class to override/hide a base class
method ?
because in c# there is the new keyword on a method.
i am looking for the same functionality as the 'final' keyword in java.

Thanks.


Use the Sealed Keyword.

--
Rob Schieber


Agreed that that stops the use of override, but it doesn't stop somone using
new - and nothing can

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Susan Baker | last post: by
10 posts views Thread by muscha | last post: by
4 posts views Thread by Nilesh | last post: by
17 posts views Thread by Bob Weiner | last post: by
8 posts views Thread by archana | last post: by
dmjpro
4 posts views Thread by dmjpro | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.