【jq】c#零基础学习之路(3)继承和虚方法

c#只能继承一个基类和多个接口(0+)

父类:Human;

class Human

  {

    public virtual Move()

    {

     Console.WriteLine("Human的虚方法");

    }

    public viod Play()

    {

      Console.WriteLine("Human的Play方法");

    }

  }

子类:Chinese;

class Chinese:Human

  {

    public override void Move()

    {

    Console.WriteLinr("这里是Chinese的Move");

    }

  }

 

试验代码:

Chinese Ch=new  Chinese();

Ch.Move();//这里Human的方法被重写

Ch.Play();

 

虚方法 关键字   virtual ,override。

posted @ 2016-06-29 21:04  2z1h5  阅读(139)  评论(0编辑  收藏  举报