Can an outer class access the members of inner class?

user707549 picture user707549 · Apr 24, 2011 · Viewed 41k times · Source

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?

Answer

AbdullahC picture AbdullahC · Apr 24, 2011

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.

Can inner class access members of outer class?

Yes, including the ones declared private, just as any instance method can.