sachin
sachin

Reputation: 1386

Access Outer Class this instance

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

Upvotes: 20

Views: 6055

Answers (2)

alasdairg
alasdairg

Reputation: 2118

Just call

A.this.hello()

Upvotes: 27

Aaron Digulla
Aaron Digulla

Reputation: 328556

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).

Upvotes: 16

Related Questions