
Untitled
By: a guest on
May 28th, 2012 | syntax:
None | size: 1.48 KB | hits: 13 | expires: Never
C# abstract classes inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace A_work_2
{
public abstract class Vehicle
{
public string vehicleName;
public abstract void Display();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace A_work_2
{
public class Vehicle4Wheels : Vehicle
{
public override void Display()
{
Console.WriteLine("Car with four wheels.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace A_work_2
{
public class SportCar : Vehicle4Wheels {
public override void Display()
{
Console.WriteLine("Sport version of the car.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace A_work_2
{
public class Rally : SportCar
{
private double motorPower = 408;
private double carWeight = 2380;
private double carAcceleration = 4.7;
private double highestSpeed = 250;
public double SpecificPower()
{
double specificPower = motorPower / carWeight;
return specificPower;
}
public override void Display()
{
Console.WriteLine("The acceleration is: {0}.nThe highest speed is {1} km/h.", carAcceleration, highestSpeed);
Console.WriteLine("Specific power is {0}", SpecificPower());
}
}
}
private double carWeight;
Vehicle sportCar = new SportCar();
sportCar.Display();
Vehicle rally = new Rally();
rally.Display();