override Abstract method - CSharp Custom Type

CSharp examples for Custom Type:virtual

Description

override Abstract method

Demo Code

using System;// w w w .jav  a 2  s  .c o  m
abstract class Car
{
   private uint odometer = 0;
   protected uint Odometer
   {
      set
      {
         odometer = value;
      }
      get
      {
         return odometer;
      }
   }
   public abstract void MoveForward();
}
class RacingCar : Car
{
   public override void MoveForward()
   {
      Console.Write("Moving dangerously fast forward... ");
      Odometer += 30;
      Console.WriteLine("Odometer in racing car: {0}", Odometer);
   }
}
class FamilyCar : Car
{
   public override void MoveForward()
   {
      Console.Write("Moving slowly but safely forward...");
      Odometer += 5;
      Console.WriteLine("Odometer in family car: {0}", Odometer);
   }
}
class CarTester
{
   public static void Main()
   {
      RacingCar myRacingCar = new RacingCar();
      FamilyCar myFamilyCar = new FamilyCar();
      myRacingCar.MoveForward();
      myFamilyCar.MoveForward();
   }
}

Result


Related Tutorials