File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class Vs Outer 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class Vs Outer Class" Watch "Inner class Vs Outer Class" New topic
Author

Inner class Vs Outer Class

Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
Hi All..
I need a clarification regarding innner classes
Please go through below code:


After explicitly assiging null value to outer class reference variable.. how it still able to access variable i?
why relation ship not borken between inner object and outer object...even after assigning null to outer object?

Is my self satisfaction answer correct?
Inner class object does't depend on outer class reference...to invoke outer class member...
becuase the outer instance address already known to inner onject when it is instantied..

Thus inner object can access outer member even after outer object assigned to 'null'.




Is it possible to break relationship?

Thank you for reading my big query...
I will be greatful for your comments...

Regards..
Ramakrishna Nalla
[ July 25, 2005: Message edited by: Ramakrishna Nalla ]
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
Is this pictures resemblance inner and outer objects relation ship?

Thank you..
Prasanta Chinara
Ranch Hand

Joined: Jul 20, 2005
Posts: 30
An inner class (non static) instance always has an associated instance of an outer class.

Setting a class variable to null - does not change anything for the instance! If another variable (in this case the inner class) holds a reference (here indirectly) to the class instance, the instance exists. It stays and is not even eligible for garbage collection.

Hope that helps.
sameer inamdar
Ranch Hand

Joined: Jul 04, 2005
Posts: 40
can we say that.
The reference to inner object is independent to the reference of Outer object.


Dream!!! Set Vision !! Transform Vision to Mission by Actions on Deadlines!.
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61

Originally posted by:sameer inamdar
can we say that.
The reference to inner object is independent to the reference of Outer object.



Yes..my above program showing that only...

I need All your replies...

your replies will be appreciate...Waiting..

RK
Robert Hayes
Ranch Hand

Joined: Oct 24, 2004
Posts: 116
I answered quite a few questions here for another poster:

http://www.coderanch.com/t/375815/java/java/inner-class-instantiation-outside-outer

Hope it helps.
 
 
subject: Inner class Vs Outer Class