Friday, February 20, 2015

Method Hiding in C#

If the derived class doesn't want to use methods in base class , derived class can implement the same method in derived class with same signature. For example in the classes given below, DriveType() is implemented in the derived class with same signature. This is called Method Hiding.

class Car
{
public void DriveType()
{
Console.WriteLine("Right Hand Drive");
}
}

class Ford : Car
{
public void DriveType()
{
Console.WriteLine("Right Hand ");
}
}

1 comment: