The Vehicle class has abstract members that must be implemented by the Car class or any other class that is inherited from the Vehicle class.
The Vehicle class has three abstract members, two properties, Distance and Time and a method, Speed.
using System;
namespace AbstractExample
{
abstract class Vehicle
{
public abstract double Distance { get; set; }
public abstract double Time { get; set; }
public abstract double Speed();
}
class Car : Vehicle
{
double mDistance, mTime = 0.0;
public override double Distance
{
get
{
return mDistance;
}
set
{
if (value <= )
{
mDistance = ;
}
else
{
mDistance = value;
}
}
}
public override double Time
{
get
{
return mTime;
}
set
{
if (value <= )
{
mTime = ;
}
else
{
mTime = value;
}
}
}
public override double Speed()
{
double speed = 0.0;
double hours = mTime / ;
speed = mDistance / hours;
return speed;
}
}
class Program
{
static void Main(string[] args)
{
double speed = 0.0;
Car objCar = new Car();
Console.WriteLine("Enter the Distance");
objCar.Distance = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the time in minutes");
objCar.Time = Double.Parse(Console.ReadLine());
speed = objCar.Speed();
Console.WriteLine("Car speed is {0:0.00}", speed);
Console.Read();
}
}
}