• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt About Inner Class (Accesing variable)

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Variable is x is declared as non-static member in Outer as well as Inner class. How to refer variable x of outer class in inner class (at line marked 1). this.x will refer to x of inner class.
Code
-------------------------
public class QryOuterInner
{
private int x = 100;
public class Inner
{
private int x = 200;
public void aMethod()
{
System.out.println("outer x = "+x); // 1
System.out.println("inner x = "+x);
}
}
public static void main(String[] args)
{
QryOuterInner.Inner in = new QryOuterInner().new Inner();
in.aMethod();
}
}
----------------------
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sujit.
for outer class its
QryOuterInner.this.x
Jaya Murugan
 
Sujit Kurtadikar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jaya,
Thanks for clarifying my doubt. Its really treaky, I didn't though like this. Thanks.
sujit
reply
    Bookmark Topic Watch Topic
  • New Topic