class Boat
{
string RegistrationNo;
string Length;
string Manufacturer;
string Year;
public Boat() {
RegistrationNo = "an001";
Length = "15";
Manufacturer = "me";
Year = "2010";
}
public virtual string ToallString()
{
return "RegistrationNo:" + RegistrationNo + "\nLength:" + Length + "\nManufacturer:" + Manufacturer + "\nYear:" + Year;
}
}
Sailboat類
class Sailboat:Boat
{
string KeelDepth;
string No;
string Type;
public Sailboat()
{
KeelDepth="45";
No="436352";
Type="sfsa35645";
}
public override string ToallString()
{
return base.ToallString() +
"\nKeelDepth:" + KeelDepth +
"\nNo:" +No+"\nType" +Type;
}
}
Powerboat類
classPowerboat:Boat
{
string NumberEngines="xxxxxxxx";
string FuelType="xxxxxxxxx";
public Powerboat()
{
NumberEngines="2";
FuelType="gas";
}
public override string ToallString()
{
return base.ToallString() +
"\nNumberEngines:" + NumberEngines +
"\nFuelType:" +FuelType;
}
}
測試類:
class Test
{
public static void Main(string[] args){
Boat boat = new Boat();
Console.WriteLine(boat.ToallString());
Console.WriteLine("+++++++++++分割線+++++++++++");
Sailboat s = new Sailboat();
Console.WriteLine(s.ToallString());
Console.WriteLine("+++++++++++分割線+++++++++++");
Powerboat p = new Powerboat();
Console.WriteLine(p.ToallString());
}
}
本程序只是Window控制臺應用程序,還可以做成Windows應用程序。好好改改就能完成任務啦。