派生类可以调用基类的方法:
    1、通过使用base关键字;
    2、派生类在访问基类的时候有一定的限制,不能访问private的成员;internal的基类成员只能被同一个程序集中的派生类访问。

示例:
public class Account
{
   public double balance;
   public bool Withdraw(double amt)
   {
       balance -=amt;
       return true;
   }
}


public class CheckAccount:Account
{
   public bool Withdraw(double amt)
   {
      if (amt <= base.balance)
      {
         return base.Withdraw(amt);
       }
      else
      {
         return false;
      }
   }
}

相关文章:

  • 2021-09-06
  • 2022-12-23
  • 2022-02-26
  • 2021-12-19
  • 2021-06-19
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2022-01-27
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-03-08
  • 2022-12-23
相关资源
相似解决方案