CHAPTER 14 BUILDING AND CONFIGURING CLASS LIBRARIES
public abstract void TurboBoost();
}
public Car(){}
public Car(string name, int maxSp, int currSp)
{
PetName = name; MaxSpeed = maxSp; CurrentSpeed = currSp;
}
}
Now assume you have two direct descendants of the Car type named MiniVan and SportsCar. Each
overrides the abstract TurboBoost() method by displaying an appropriate message via a Windows Forms
message box. Insert a new C# class file into your project, named DerivedCars.cs, which contains the
following code:
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
// Keep reading! This won't compile until you reference a .NET library.
using System.Windows.Forms;
namespace CarLibrary
{
public class SportsCar : Car
{
public SportsCar(){ }
public SportsCar(string name, int maxSp, int currSp)
: base (name, maxSp, currSp){ }
public override void TurboBoost()
{
MessageBox.Show("Ramming speed!", "Faster is better...");
}
}
public class MiniVan : Car
{
public MiniVan(){ }
public MiniVan(string name, int maxSp, int currSp)
: base (name, maxSp, currSp){ }
}
}
516
public override void TurboBoost()
{
// Minivans have poor turbo capabilities!
egnState = EngineState.engineDead;
MessageBox.Show("Eek!", "Your engine block exploded!");
}