覆盖和可覆写 [英] Overrides & Overridable

查看:68
本文介绍了覆盖和可覆写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好团队,

我正在从VB迁移到VB.NET.在处理继承时,我遇到了一个问题.我创建了一个大师班和派生班.我在主类和派生类中使用了具有相同签名的函数.根据标准,基类方法应以OVERRIDABLE为前缀,派生类方法应以OVERRIDES为前缀.即使我没有这样做,我的程序仍在运行.但是,VB.NET显示警告,但没有中断程序运行.这背后的原因是什么?

后来,当我从现有的派生类派生另一个子类时,VB.NET显示错误,即方法签名应具有OVERRIDABLE&.覆盖.

有人可以解释这种现象吗?

提前谢谢.
克里希纳(Krishna).

Hello Team,

I am migrating myself into VB.NET from VB. While I was working with Inheritance, I stucked up with an issue. I have created a Master and Derived classes. I used a function with same signature in both master and derived classes. As per the standards, the base class method should be prefixed with OVERRIDABLE and the derived class method should be prefixed with OVERRIDES. Even if I am not doing this my program is still working. However, VB.NET is showing a warning but not interuppting the program run. What is the reason behind this?

Later when I derived another sub class from the existing dervied class, VB.NET shows error that the method signatures should have OVERRIDABLE & OVERRIDES.

Could someone explain this phenomenon?

Thanks in advance.
Krishna.

推荐答案

如果您不使用OVERRIDES,则仍在使用此方法作为新方法.
Shadows 关键字放在该方法的前面将消除该错误.

您的子类不包含Overriable方法,因此您会收到错误消息.
If you dont use OVERRIDES, you are still using this method as a new method.
Putting the Shadows keyword in-front of the method will remove the error.

Your sub-class does not contain an Overriable method so you get the error.


这篇关于覆盖和可覆写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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