Java 类可访问性 [英] Java Class Accessibility
问题描述
与我的其他问题略有相关:以下有什么区别:>
Slightly related to my other question: What is the difference between the following:
private class Joe
protected class Joe
public class Joe
class Joe
再说一次,最后两个的区别是我最感兴趣的.
Once again, the difference between the last 2 is what I'm most interested in.
推荐答案
任何包中的类都可以访问公共类.
A public class is accessible to a class in any package.
具有默认访问权限的类 (class Joe
) 仅对同一包中的其他类可见.
A class with default access (class Joe
) is only visible to other classes in the same package.
private 和protected 修饰符只能应用于内部类.
The private and protected modifiers can only be applied to inner classes.
私有类只对其封闭类可见,同一个封闭类中的其他内部类也可见.
A private class is only visible to its enclosing class, and other inner classes in the same enclosing class.
受保护的类对同一包中的其他类以及扩展封闭类的类可见.
A protected class is visible to other classes in the same package, and to classes that extend the enclosing class.
这篇关于Java 类可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!