标签:
在父类中定义一系列的抽象行为,具体的实现交由子类去实现,类似于ppt的模版,具体实现总是由我们自己去书写ppt。
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ConsoleApplication1 { class Program { public abstract class Dish { public void Cook() { StrikeFire(); PutOil(); PutSoil(); PutFood(); TurnOffFire(); } public void StrikeFire() { Console.WriteLine("strike fire"); } public void PutOil() { Console.WriteLine("put oil"); } public void PutSoil() { Console.WriteLine("put soil"); } /// <summary> /// 具体放什么交由子类去完成 /// </summary> public abstract void PutFood(); public void TurnOffFire() { Console.WriteLine("turn off fire"); } } public class Meat : Dish { public override void PutFood() { Console.WriteLine("put meat"); } } static void Main(string[] args) { Meat meat = new Meat(); meat.Cook(); } } }
标签:
原文地址:http://www.cnblogs.com/zkzk945/p/5111762.html