如何隐藏静态方法 [英] How to hide static method

查看:67
本文介绍了如何隐藏静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个这样的课程:

Let's say I have a classes, like that:

class A
{
   public static int Count()
}
class B : A
{
}
class C : A
{
}

如何为类B而不是对于C隐藏此静态方法?

How can I hide this static method for class B but not for C?

推荐答案

基本上,您不能.哎呀,如果它是公开的,那么任何人都可以叫它.

You can't, basically. Heck, if it's public then anyone can call it.

您可以对其进行保护,从而可以在B或C内调用它,但不能在其他地方调用它...但是您仍然无法区分B和C.

You could make it protected which would allow it to be called from within B or C but not elsewhere... but you still couldn't differentiate between B and C.

这篇关于如何隐藏静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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