wood burning stoves*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 14114
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How all non static member of outer class are available to the non static method in inner class