参考代码:
using System; namespace InterfaceDemo { /// <summary> /// 定义一个爬树接口 /// </summary> interface IClimbTree { void ClimbTree(); } /// <summary> /// 定义一个抓老鼠接口 /// </summary> interface ICatchMouse { void CatchMouse(); } /// <summary> /// 定义站立行走接口 /// </summary> interface IStandWalk { void StandWalk(); } /// <summary> /// 定义一个宠物类 /// </summary> public class Pet { public void Run() { Console.WriteLine("我会跑"); } } /// <summary> /// 猫类,继承于宠物类,又实现了爬树和抓老鼠接口 /// </summary> public class Cat : Pet, IClimbTree, ICatchMouse { public void ClimbTree() { Console.WriteLine("我会爬树"); } public void CatchMouse() { Console.WriteLine("我会抓老鼠"); } } /// <summary> /// 站立猫类,继承于猫类,又实现了站立行走接口 /// </summary> public class StandCat :Cat, IStandWalk { public void StandWalk() { Console.WriteLine("我会站立行走"); } } class Program { static void Main(string[] args) { Cat cat = new Cat(); cat.Run(); cat.ClimbTree(); cat.CatchMouse(); StandCat standCat = new StandCat(); standCat.StandWalk(); Console.ReadLine(); } } }
标签:Console,C#,Demo,void,接口,Cat,WriteLine,Interface,public From: https://www.cnblogs.com/exesoft/p/16965262.html