Override vs Name Hiding

  • Thread starter Thread starter Justin Rogers
  • Start date Start date
J

Justin Rogers

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.
 
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
 
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.
 
Back
Top