我怎么称呼基础班? [英] How can i call base class?
本文介绍了我怎么称呼基础班?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 thePerson
class that calls it''sSalaray
function and call that from theManager
class. You would need to make sure that a function with the same name was never defined in theEmployee
class.
这篇关于我怎么称呼基础班?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文