• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Explaination reg inner classes

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can any one explain me below program as what is haapening and why did we used this to call flag and whats the use of using that .
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
As you know inner class can access the instance variables of the outer class. There are two ways to access a instance variable from within a inner class.
First:
if (Test4.this.flag)
Second:
if (flag)

Second method access flag directly because inner classes can access the outer class instance members, Here inner classes implicit access to the this object of outer class, this is because inner class instance cannot exists wihtout an outer class instance, so when an inner class is instantiated compiler will implicitly pass the outer class instance to it which was used to create the inner class instance.
Second is preffered way to do so.

First one is also legal here you explicitly say this object of class Test4.
Thanks
Deepak
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic