This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How all non static member of outer class are available to the non static method in inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How all non static member of outer class are available to the non static method in inner class" Watch "How all non static member of outer class are available to the non static method in inner class" New topic
Author

How all non static member of outer class are available to the non static method in inner class

siddharth das
Ranch Hand

Joined: Aug 17, 2007
Posts: 124
Hi,

Can you please tell the logic behind this.

How all non static member of outer class are available to the non static method in inner class?

Thanks,
Siddharth
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

When you have a non-static nested class, each instance of that nested class is associated with an instance of the enclosing class. Have a look at this:

Note how I create the new instance of Example in line 14: Example example = main.new Example();. So I'm creating a new Example object here that is associated with a specific instance of class Main. The instance of Example can access the member variables, such as id, of that instance of Main.

That's just how non-static nested classes work in Java.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
siddharth das
Ranch Hand

Joined: Aug 17, 2007
Posts: 124
Thanks a lot.
 
jQuery in Action, 2nd edition
 
subject: How all non static member of outer class are available to the non static method in inner class
 
Similar Threads
can inner class call outer class method?
classes working not understood
accessibility modifiers for classes
non-static inner class
Inner Access specifiers