GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How  to decide  whether to use inner class or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How  to decide  whether to use inner class or not " Watch "How  to decide  whether to use inner class or not " New topic
Author

How to decide whether to use inner class or not

Anup Katariya
Greenhorn

Joined: Oct 23, 2002
Posts: 29

In above code, in my case, object1 is meaningless if object2List is null, but independent object2 has also no meaning.
So are they tightly coupled here? or they are just in one java file instead of two?
What are other possibilities, where I would need this kind of thing?
Thanks
Anup


SCJP
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Welcome to the Ranch Anup.
I have not got exactly what you are asking, but I will try anyway.
In order to create an instance of the inner class an object of the outer class is needed. The inner instance receives a reference to the outer in its constructor ans uses it to access any of the outer members, even the private ones. Thus I will say that the two instances are tightly coupled.
You can see examples in Thinking in Java
[ November 01, 2002: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
 
GeeCON Prague 2014
 
subject: How to decide whether to use inner class or not