This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • 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,
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic