In inheritance, if we need to hide the base class function into derived class then we use the concept of name hiding.

Example of Name Hiding

In the following example, we have created Abc class which is our base class and Pqr Class which is our derived class. In the base class Abc we have declared sum function and hide it in derived class by using new keyword. If we do not use new keyword, we will get warning but it does not affect programme.



		
public class Abc
{
    public int sum(int x, int y)
    {
        return (x + y);
    }
}
public class Pqr : Abc
{
    public new int  sum(int x, int y)
    {
        return (x + y) * 2;
    }
}



Now when we create the object of Pqr class and call the sum function, it will call the derived class function.

		
Pqr pq = new Pqr();

Response.Write( pq.sum(4, 5));


Therefore, we simply hides the base class function into derived class.