我怎么称呼基础班? [英] How can i call base class?

查看:123
本文介绍了我怎么称呼基础班?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public Class Manager
    Inherits Employee
    Public Overrides Sub Salary()
      '' MyBase.Salary
      '' I want to call Person.Salary instead of Employee Salary, is this possible. How can i call the base base class from the top Inherits class.
    End Sub
End Class

Public Class Employee
    Inherits Person

    Public Overrides Sub Salary()
      '' has many logic to calcuate for employee
    End Sub
End Class

Public Class Person
   Public Overridable Sub Salary()
      '' has many logic to do calculate for person
   End Sub

End Class

推荐答案

public class Person
{
    public virtual void Salary()
    {

    }
}

public class Employee : Person
{
    public override void Salary()
    {
        // Person.Salary
        base.Salary();
    }
}

public class Manager : Employee
{
    public override void Salary()
    {
        // Employee.Salary
        base.Salary();
    }
}



如果您不希望一个类调用其基类方法,则由您来实现逻辑.



If you don''t want one class to call its base class method it is up to you to implement the logic.


没有语言支持的方法.

您可以在Person类中添加一个单独的受保护函数,以调用其Salaray函数,然后从Manager类进行调用.您需要确保在Employee类中从未定义具有相同名称的函数.
There is no language supported way to do this.

You could add a separate protected function to the Person class that calls it''s Salaray function and call that from the Manager class. You would need to make sure that a function with the same name was never defined in the Employee class.


这篇关于我怎么称呼基础班?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆