When you have a non-static nested class, each instance of that nested class is associated with an instance of the enclosing class. Have a look at this:
Note how I create the new instance of Example in line 14: Example example = main.new Example();. So I'm creating a new Example object here that is associated with a specific instance of class Main. The instance of Example can access the member variables, such as id, of that instance of Main.
That's just how non-static nested classes work in Java.