Static nested classes 1 exactly correspond to outer classes, except that they have access to all members of the outer class, regardless of access qualifier. They exist separately from any instance of the outer class, so you need a reference to the instance to access any instance variables or non-stationary methods of the outer class.
Non-static nested classes (called inner classes) arise only in the context of an instance of an outer class. When building, they automatically generate a second this field, with which you can access from the inner class using the Outer.this syntax. Each instance of the inner class is enclosed in one instance of the outer class. Again, all permissions of static nested classes apply to inner classes. But since they already have an instance of the outer class, it can automatically access instance variables and methods of the outer class.
For a pleasant (and very detailed) discussion of inner classes and access specifiers, you can read the inner class specification . It describes, among other things, how a nested class gains access to private members of its outer class (s). Softer reading is a Nested Class Tutorial .
Disable topic: suppose you have this class structure:
public class O { public O() { ... } public class I {
and you created an instance of O :
O outer = new O();
Now suppose you want to instantiate an OI . you cannot just use new OI() because the new instance of I must be enclosed in a specific instance of O For this, Java provides the following syntax:
OI inner = outer.new OI();
Then inner will have a second this field specified as outer .
Note that this "qualified syntax for the new operator is only used for inner classes; it would not be necessary (essentially an error) if I were a nested static class.
1 You often come across the phrase โstatic inner classโ (including, embarrassingly, in an earlier version of this answer). This is the wrong terminology. In Java, "inner classes" are specially non- static nested classes.