vb.net类属性是继承的吗?

托比

类的属性是由派生类继承的,还是必须专门应用于派生类?

例如,system.timer.timer:

'Declaration
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True,  _
    ExternalThreading := True)> _
Public Class Timer _
    Inherits Component _
    Implements ISupportInitialize

如果我能上课

Class MyScheduler
    Inherits Timer
    '...
End Class

我是否需要将计时器calss的属性显式应用到MyScheduler类,或者这是继承的一部分?

卡尔·安德森

默认情况下,属性不会被继承,但是您可以通过使用Inherited:=True属性上的语法使它们可继承,如下所示:

<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True,  _
ExternalThreading := True, Inherited:=True)> _
Public Class Timer _
    Inherits Component _
    Implements ISupportInitialize

现在,任何派生自的类Timer也将具有Timer该类的属性,而子类属性将覆盖二者之间的所有冲突。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章