问题描述
大家好,
众所周知,在接口中,所有方法都必须是公共的,我们不能定义私有或受保护的方法.如果我们尝试尝试,则编译器将给出错误,因为它定义了接口.
我的问题是,为什么接口不接受除public之外的访问修饰符,其背后的原因是什么?
在此先感谢:)
--Amit
Hi to all,
As we know in an interface all methods must be public, we can not define private or protected methods. If we will try then compiler will give the error because its definition of the interface.
My question is why interfaces do not accept access modifiers other then public and what are the reasons behind it?
Thanks in advance :)
--Amit
推荐答案
我的问题是,为什么接口不接受除公共之外的访问修饰符,这是什么原因??
my question is, Why interfaces not accept access modifiers other then public, what is the reason behind this???
非公共接口背后的原因是什么? :)
一个类的所有非公共方法都可以直接访问
(,如果您有适当的此上下文...
...在接口调用中不是这种情况):)
What would be a reason behind non-public interfaces ? :)
All non-public methods of a class could be accessed directly
(, if you have an appropriate this-context...
...that is not a case at an interface call) :)
这篇关于界面中的访问修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!