关于继承的另一个问题 [英] Another question on Inheritance
问题描述
Public MustInherit Class My3rdLevelClass
继承GeneratedClass
公共共享函数GetSomething()As String
返回Something
结束函数
在上面的示例中,我已将该类声明为MustInherit。
我对GetSomething方法的范围有疑问。
我可以直接从同一个项目的类中调用它。
应该设置什么才能允许继承它的类
使用它的能力。但这不允许任何人直接打电话给它?
-
Joe Fallon
Public MustInherit Class My3rdLevelClass
Inherits GeneratedClass
Public Shared Function GetSomething() As String
Return "Something"
End Function
In the sample above I have declared the class as MustInherit.
I have questions about the scope of the GetSomething method.
I was able to call it directly from a class in the same project.
What should it be set to in order to allow a class that inherits it the
ability to "use it" but that does not allow anyone to call it directly?
--
Joe Fallon
推荐答案
你好乔,
这是你之后的受保护关键词。对于当前类和所有派生类可用的方法
。
问候,
Fergus
Hi Joe,
That''s the Protected keyword you''re after there. For methods
that are available to the current class and all derived classes only.
Regards,
Fergus
*" Joe Fallon" < JF ****** @ nospamtwcny.rr.com> scripsit:
* "Joe Fallon" <jf******@nospamtwcny.rr.com> scripsit:
Public MustInherit Class My3rdLevelClass
继承GeneratedClass
公共共享函数GetSomething()As String
返回" ;某些东西
结束功能
在上面的示例中,我已将该类声明为MustInherit。
我对GetSomething的范围有疑问方法。
我能够直接从同一个项目中的一个类调用它。
为了让一个继承它的类能够使用它应该设置什么呢?它"但这不允许任何人直接调用它?
Public MustInherit Class My3rdLevelClass
Inherits GeneratedClass
Public Shared Function GetSomething() As String
Return "Something"
End Function
In the sample above I have declared the class as MustInherit.
I have questions about the scope of the GetSomething method.
I was able to call it directly from a class in the same project.
What should it be set to in order to allow a class that inherits it the
ability to "use it" but that does not allow anyone to call it directly?
将其修饰符设置为''受保护''。
- -
Herfried K. Wagner
MVP·VB Classic,VB.NET
< http://www.mvps.org/dotnet> ;
Set its modifier to ''Protected''.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Fergus,
我尝试使用受保护的(和受保护的朋友),但它似乎没有工作
right。
你记得我有4个级别的课程。
当他们都是公共共享时,他们工作正常。
我只是使用如下语法:
4thLevelClassName.SomeMethod
(SomeMethod是公共的,处于1,2或3级)
但是当我使SomeMethod成为受保护的函数时,第4级无法
看到即使它继承了它。
我想我在这里遗漏了一些东西。
你能开导我吗?
-
Joe Fallon
" Fergus Cooney" <音响***** @ post.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
Fergus,
I tried using Protected (and Protected Friend) but it didn''t seem to work
right.
As you recall I have 4 levels of classes.
When they are all Public Shared, they work fine.
I just use syntax like:
4thLevelClassName.SomeMethod
(SomeMethod is Public and is in Level 1,2 or 3)
But when I made SomeMethod a Protected function, the 4th level could not
"see" it even though it inherited it.
I think I am missing something here.
Can you enlighten me?
--
Joe Fallon
"Fergus Cooney" <fi*****@post.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
你好Joe ,
那是你之后的受保护关键词。对于当前类和所有派生类可用的方法
问候,
Fergus
Hi Joe,
That''s the Protected keyword you''re after there. For methods
that are available to the current class and all derived classes only.
Regards,
Fergus
这篇关于关于继承的另一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!