how can i prevent overriding/hiding a base class method

G

Guest

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

Rob Schieber

yaron said:
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.
 
K

Kevin Spencer

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/CsharpVsJava.html#virtualfinal

--
HTH,

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

Guest

Thank you all.

Kevin Spencer said:
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/CsharpVsJava.html#virtualfinal

--
HTH,

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

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