20

how do we access outer class this instance: eg in

Class A {

   Class B {

      this.helloB();
      (A's this).hello()
   }
}

how do we access A's this instance in Java

skaffman
  • 398,947
  • 96
  • 818
  • 769
sachin
  • 1,376
  • 2
  • 15
  • 37

2 Answers2

27

Just call

A.this.hello()
alasdairg
  • 2,108
  • 12
  • 14
16

By prefixing this with the class: A.this.hello()

Similarly, when you want to create an instance of B outside of A, you can use a.new B() (where a instanceof A == true).

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820