• 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

Accessing a superclass's method of and instance of outter class from static inner class

 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Class A contains static class B that has static methodB. Class A extends class C and inherits its public methodC.
I want to access methodC from methodB. I need to be sure that the instance of Class A that I call methodB from is used in methodB.
How?

Thanks,
John,
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the inner class B is static, you can't access any instance methods or fields from its outer class A. This is just like static methods--if a method is static, you can't access instance members either.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me like class B may need to be non-static; it then gets an automatic reference to its enclosing instance of class A. It can then simply call "methodC". If that would cause name clashes you can use A.this.methodC -- the A.this is the reference to the enclosing instance.
 
reply
    Bookmark Topic Watch Topic
  • New Topic