如何在派生类中将公共虚方法重写为私有? [英] How can I override a public virtual method to be private in my derived class?

查看:118
本文介绍了如何在派生类中将公共虚方法重写为私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有覆盖公共虚拟方法或属性,以便它在我的派生类中是私有的?$ / b

我尝试使用新的财产和私有,但没有运气。


-

------------------ -----------------

Ken Varn

高级软件工程师

Diebold Inc.


EmailID = varnk

Domain = Diebold.com

--------------- --------------------

Is there anyway to override a public virtual method or property so that it
is private in my derived class?

I tried using new on the property and making it private, but no luck.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

推荐答案

public sealed overrides function()

{

}


" Ken Varn" < NOSPAM>在消息中写道

新闻:美国************** @ tk2msftngp13.phx.gbl ...
public sealed overrides function()
{
}

"Ken Varn" <nospam> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
无论如何要覆盖一个公共虚拟方法或属性,以便它在我的派生类中是私有的吗?

我尝试在属性上使用new并将其设为私有,但没有运气。

-
-----------------------------------
Ken Varn <高级软件工程师
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
------------- ----------------------
Is there anyway to override a public virtual method or property so that it
is private in my derived class?

I tried using new on the property and making it private, but no luck.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------



OOps,那只是封条这样你就不能再继承了......我不认为这就是你想要的......我不确定你是否可以改变

上面的访问修饰符...嗯..


对不起..

- j


" Jeffrey A. Voigt" < VO *********** @ myfloridahouse.com>在消息中写道

news:uy ************* @ TK2MSFTNGP12.phx.gbl ...
OOps, that just seals it so that you cannot inherit from it again.... I
don''t think that is what your looking for... I''m not sure if you CAN change
the access modifier on it... hmm..

Sorry..
- j

"Jeffrey A. Voigt" <vo***********@myfloridahouse.com> wrote in message
news:uy*************@TK2MSFTNGP12.phx.gbl...
public sealed overrides function()
{
}

Ken Varn < NOSPAM>在消息中写道
新闻:美国************** @ tk2msftngp13.phx.gbl ...
public sealed overrides function()
{
}

"Ken Varn" <nospam> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
无论如何都要覆盖公共虚拟方法或者属性,以便
在我的派生类中是私有的吗?

我尝试在属性上使用new并将其设为私有,但没有运气。

-
-----------------------------------
Ken Varn
高级软件工程师
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
----------------- ------------------
Is there anyway to override a public virtual method or property so that it is private in my derived class?

I tried using new on the property and making it private, but no luck.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------






" Ken Varn"写道...

"Ken Varn" wrote...
是否有覆盖公共虚拟
方法或属性,以便它在我的派生类中是私有的?


如果你只是在课堂上使用它,那么覆盖它有什么意义




为什么不简单地使用该方法的其他名称?

我尝试在属性上使用new并将其设为私有,但没有运气。
Is there anyway to override a public virtual
method or property so that it
is private in my derived class?
What would be the the point in overriding it
at all if you''ll just be using it inside that class?

Why not simply use another name for that method?
I tried using new on the property and
making it private, but no luck.




如果你是从一个类中派生出来的,那么你必须将

超类中的操作视为契约。不要被侵犯。你可以在超级类的实例上执行的任何操作,你必须能够在

子类的实例上做(Liskov原理)。


因此,你不能让继承的操作比在

超类中更受限制。


一点继承是多态性的可能性,你在
中有些情况下不知道实例是超类还是派生的

类。无论方法是否被覆盖,它仍然必须能够响应超类的操作,

。如果方法被覆盖(例如空方法),则取决于子类

,但它们仍然必须能够响应操作。


// Bjorn A



If you have derived from a class, you''ll have to see the operations in the
superclass as a "contract" not to be violated. Any operations you can do on
an instance of the superclass, you must be able to do on instances of the
subclasses (Liskov''s principle).

Hence, you cannot make an inherited operation more restricted than in the
superclass.

One point of inheritance is the possibility of polymorphism, where you in
some cases don''t know if the instance is of the superclass or a derived
class. It must still be able to respond to the operations of the superclass,
regardless if the methods are overridden or not. It''s up to the subclasses
if the methods are overridden (with e.g. "empty" methods), but they still
must be able to respond to the operation.

// Bjorn A


这篇关于如何在派生类中将公共虚方法重写为私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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