Example of Method Hiding in C#

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 1533
Method Hiding occurs when some Derived Class inherits the Base Class and the type signature of Methods in Base class are same.

We say the base class method has hided behind derived class method.

Sample Example:

using System;

class BaseClass
{
public void Display()
{
System.Console.WriteLine("BaseClass::Display Method");
}
}

class DerivedClass : BaseClass
{
public void Display()
{
System.Console.WriteLine("DerivedClass::Display Method");
}
}

class MethodHidingDemo
{
public static void Main()
{
DerivedClass obj = new DerivedClass();
obj.Display();

Console.Read();
}
}

Comments or Responses

Login to post response