学习C#高级编程--方法重写和隐藏

把一个基类函数声明为virtual,就可以在任何派生类中重写了:

class MyBaseClass

{

public virtual string VitualMethod()

{

return "virtual Method and defind in MyBaseClass";

}

}

派生类重写基类的函数时,要使用override关键字显式声明:

 

class MyDerivedClass:MyBassClass

{

public override string VirtualMethod()
{

return  "override defind in MyDerivedClass";

}

}

 

 

posted on 2008-11-29 10:25  SUNJUNLIN  阅读(363)  评论(0编辑  收藏  举报

导航