接口声明的访问说明符
为什么 protected/private 访问说明符不能用于接口声明?
Why protected/private access specifier cannot be used Interfaces declaration ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
为什么 protected/private 访问说明符不能用于接口声明?
Why protected/private access specifier cannot be used Interfaces declaration ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
您可以声明一个受保护的类或者实际上是一个私有的类 - 但只能在另一个类中声明。此时,它要么对从外部派生的类可见(在受保护的情况下),要么对从外部派生的类可见(在私有的情况下):
You can declare a protected class or indeed a private one - but only within another one. At that point it's either visible to classes derived from the outer one (in the case of protected) or not (in the case of private):
私人课程是什么意思?它不能在这个类之外使用吗?为什么要上这样的课? (您将如何运行/测试它?)
受保护的类意味着什么?它只能被扩展它的类看到。因此,当您键入一个类骨架(某些在世界之外)时,它是不可见的,但是当我们说扩展时,该类动态地变得可见?
包受保护的类是有意义的 - 它对包内的类可见,但并不真正供公众使用。
What does a private class mean? That it cannot be used ever outside this class? Why would you ever have such a class? (How would you run/test it?)
What would a protected class mean? That it can only be seen by classes that extend it. So when you type a class skeleton (some where outside the world) it is not visble but when we say extends the class dynamically becomes visible?
Package protected class makes sense - It is visible to the classes inside the package and not really for public consumption.
为类或接口使用私有或受保护的访问说明符是没有意义的,因为当涉及到用于实现数据封装的变量或方法时,这两个说明符更有意义。
There is no sense in having private or protected access specifiers for class or interface because these two makes more sense when it comes to variables or methods for achieving encapsulation of the data.
Java 中不存在访问说明符之类的东西。该术语是“访问修饰符”。
(所以你看到的所有询问有什么区别的面试问题都是无稽之谈。)
There is no such thing as an access specifier in Java. The term is 'access modifier'.
(So all those interview questions you see asking what is the difference are nonsense.)