欢迎光临
我们一直在努力

c#.net中类的覆写(OverRide)-.NET教程,C#语言

建站超值云服务器,限时71元/月

public class mybase
{
   public virtual string meth1()
   {
      return “mybase-meth1”;
   }
   public virtual string meth2()
   {
      return “mybase-meth2”;
   }
   public virtual string meth3()
   {
      return “mybase-meth3”;
   }
}

class myderived : mybase
{
   // overrides the virtual method meth1 using the override keyword:
   public override string meth1()
   {
      return “myderived-meth1”;
   }
   // explicitly hide the virtual method meth2 using the new
   // keyword:
   public new string meth2()
   {
      return “myderived-meth2”;
   }
   // because no keyword is specified in the following declaration
   // a warning will be issued to alert the programmer that
   // the method hides the inherited member mybase.meth3():
   public string meth3()
   {
      return “myderived-meth3”;
   }

   public static void main()
   {
      myderived md = new myderived();
      mybase mb = (mybase) md;

      system.console.writeline(mb.meth1());
      system.console.writeline(mb.meth2());
      system.console.writeline(mb.meth3());
   }
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » c#.net中类的覆写(OverRide)-.NET教程,C#语言
分享到: 更多 (0)