468,765 Members | 1,119 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Override vs Name Hiding

Hi all.
I am trying to figure out the differences between
overriding and hiding a method name.
The only difference i can see, is that with name hiding i can change
the method access level.
Are there any other differences?
Thanks, Sharon.
Nov 16 '05 #1
4 3952
Name hiding only works when the developer knows the true type of the
object. For instance, if you pass a NewArrayList that is derived from ArrayList
and try to new any of the methods, then classes that only know the object is
an ArrayList and weren't coded against NewArrayList will call the base methods
rather than the *new* methods.

Virtual inheritance gets over this by grabbing the highest override of a method
in the
list. If you instead override the method in the previous example, then even
code
that works on ArrayList will call the NewArrayList version of the method.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Sharon Tal" <ta*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi all.
I am trying to figure out the differences between
overriding and hiding a method name.
The only difference i can see, is that with name hiding i can change
the method access level.
Are there any other differences?
Thanks, Sharon.

Nov 16 '05 #2
> Are there any other differences?

Yes, there are:
1. If the member of the base class it is not virtual you cannot overrride,
so the only chance to give another implementation is using new(maybe with
the same access level);
2. The members declared using "new" do not have the polymorphims
characteristic; the overrided members do have it.

Ernest
"Sharon Tal" <ta*******@hotmail.com> wrote in message
news:#R**************@TK2MSFTNGP09.phx.gbl...
Hi all.
I am trying to figure out the differences between
overriding and hiding a method name.
The only difference i can see, is that with name hiding i can change
the method access level.
Are there any other differences?
Thanks, Sharon.

Nov 16 '05 #3
Sharon Tal <ta*******@hotmail.com> wrote:
I am trying to figure out the differences between
overriding and hiding a method name.
The only difference i can see, is that with name hiding i can change
the method access level.
Are there any other differences?


See http://www.pobox.com/~skeet/csharp/faq/#override.new

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
The difference is indeed significant.
Thanks :)
"Sharon Tal" <ta*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi all.
I am trying to figure out the differences between
overriding and hiding a method name.
The only difference i can see, is that with name hiding i can change
the method access level.
Are there any other differences?
Thanks, Sharon.

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Darius | last post: by
5 posts views Thread by Mark Broadbent | last post: by
11 posts views Thread by songie D | last post: by
11 posts views Thread by z_learning_tester | last post: by
3 posts views Thread by Tom Jones | last post: by
16 posts views Thread by ssg31415926 | last post: by
3 posts views Thread by methodios | last post: by
5 posts views Thread by Marcel Hug | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.