Tuesday, July 11, 2006
what is the use of 'new' in funciton signature
class BaseClass
{
public int Add(int a, int b)
{
return a+b;
}
}
class DerivedClass:BaseClass
{
public int new Add(int a, int b)
{
return a+b;
}
}
Note: When the object of DerivedClass is used to access Add function, which of the functions is called ? It would be the one of DerivedClass. This is same even if "new" is used or not.
Then what is the use of "new" ?
Without "new" complier throws an error of ambiguity. With "new", compiler understands that the programmer knows about the ambiguity and still want the function with the signature to exist in the derived class too.