using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 接口 { class Program { static void Main(string[] args) { //接口:就是一个规范、能力 PlayingBasketball p = new NBAPlayer(); //PlayingBasketball p = new Student(); p.Basketball(); Console.ReadKey(); } } //PlayingBasketball接口 public interface PlayingBasketball { void Basketball(); //不能有访问修饰符 //string Test(); //无方法体的方法 //string Name //自动属性 //{ // get; // set; //} } //NBAPlayer类 public class NBAPlayer:PlayingBasketball { public void Basketball() { Console.WriteLine("NBA球员会打篮球"); } } //Student类:继承PlayingBasketball接口 public class Student:NBAPlayer,PlayingBasketball { public void Basketball() { Console.WriteLine("学生也会打篮球"); } } }