外部类可以访问内部类的成员吗? [英] Can an outer class access the members of inner class?
问题描述
内部类是在类中定义的类,内部类可以声明为public,private,protected。如果内部类定义为private和protected,可以外部类访问内部类的成员?并且可以是外部类的内部类访问成员?
The inner class is the class defined inside a class, and the inner class can be declared as public, private, protected. If the inner class defined as private and protected, can outer class access the members of inner class? and can inner class access members of outer class?
推荐答案
如果内部类定义为private
和protected,可以外部类访问
内部类的成员?
If the inner class defined as private and protected, can outer class access the members of inner class?
是的。这些限定符只会影响从外部类派生的类中内部类的可见性。
Yes. These qualifiers will only affect the visibility of the inner class in classes that derive from the outer class.
$ b outer class?
Can inner class access members of outer class?
是的,包括声明为 private
作为任何实例方法可以。
Yes, including the ones declared private
, just as any instance method can.
这篇关于外部类可以访问内部类的成员吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!