模拟汽车行驶
汽车类
public class Vehicle { private string xinghao; private string chandi; public Vehicle() { } public Vehicle(string xinghao,string chandi) { this.chandi = chandi; this.xinghao = xinghao; } public void VehicleRun() { Console.WriteLine("汽车在行驶"); } public string Xinghao { get { return xinghao; } set { xinghao = value; } } public string Chandi { get { return chandi; } set { chandi = value; } } }
卡车类
public class Truch:Vehicle { public Truch() { } public Truch(string chandi,string xinghao):base(xinghao,chandi) { } public void truchRun() { Console.WriteLine("型号为{0},产地为{1}的卡车正在行驶",this.Xinghao,this.Chandi); } }
Main方法
static void Main(string[] args) { Truch truch = new Truch("德国", "奥迪A6"); truch.VehicleRun(); truch.truchRun(); Console.Read(); }