Method Hiding with new modifier - CSharp Custom Type

CSharp examples for Custom Type:Method

Description

Method Hiding with new modifier

Demo Code

using System;/*from  www .  j  a v a2s. c  om*/
class Car
{
   public virtual void MoveForward()
   {
      Console.WriteLine("Move Car forward by 1 kilometer");
   }
   public void Reverse()
   {
      Console.WriteLine("Reverse Car by 50 meters");
   }
}
class FamilyCar : Car
{
   public override void MoveForward()
   {
      Console.WriteLine("Move Family Car forward by 5 kilometers");
   }
   public new void Reverse()
   {
      Console.WriteLine("Reverse the Family Car by 200 meters");
   }
}
class Tester
{
   public static void Main()
   {
      Car myCar;
      myCar = new FamilyCar();
      myCar.MoveForward();
      myCar.Reverse();
   }
}

Result


Related Tutorials