views:

35

answers:

2

Hi ... I know that when we have a virtual function in our own base class, then by overriding it in a derived class and considering casting when variable declaration, we have different result with comparison to using new modifier in the derived class. but why? Is there any logical reason for that or we have to learn it without any reason?

A: 

I assume you are referring to C#.

Basically, you use the new modifier when the subclass method has nothing to do with the superclass method. They share the name, but there is no shared polymorphic behavior. When you are polymorphically redefining the name, that is called overriding.

Matthew Flaschen
A: 

Instead of using the new operator I would recommend choosing a different name for the method.