Getting the reference to the enclosing object from an inner class

You can get the this pointer by specifying classname.this as shown in following
example:

public class Main {
   public Main() {
      class InnerMain {
         public void method() {
            System.out.println(Main.this);
         }
      }
 
      new InnerMain().method();
   }
 
   public static void main(String []args) {
      new Main();
   }
}

outputs:

Main@557046aa