The class Inner
is created only once, when your code is compiled, as @EJP commented. You can easily verify this when looking at the compilation output.
I created a .java file called Outer.java
and simply compiled it. The result was two .class files.

You can see that the compiler created a class file called Outer.class
but also a class file called Outer$1Inner.class
, which is simply your local class. Here, Java uses $1
to mark the inner anonymous classes.
Adding a main
method and calling new Outer().test();
you can see that the output is indeed 10 lines, which means 10 instances of Inner
were created. You can easily verify this by adding a hashCode()
somewhere to the output like so
System.out.println("display: outer_x = " + outer_x + " --> " + hashCode());
Which gives the following output:
display: outer_x = 100 --> 1704856573
display: outer_x = 100 --> 705927765
display: outer_x = 100 --> 366712642
display: outer_x = 100 --> 1829164700
display: outer_x = 100 --> 2018699554
display: outer_x = 100 --> 1311053135
display: outer_x = 100 --> 118352462
display: outer_x = 100 --> 1550089733
display: outer_x = 100 --> 865113938
display: outer_x = 100 --> 1442407170
Different hashcodes mean different instances.
Now all this happens, because the compiler doesn't care about control flow statements like for
when it comes to collecting classes. It sees the inner class and compiles it once. The output on the other hand happens at run time and follows control flow statements.