This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Where are Inner Classes used (except for the SCJP test)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Where are Inner Classes used (except for the SCJP test)?" Watch "Where are Inner Classes used (except for the SCJP test)?" New topic
Author

Where are Inner Classes used (except for the SCJP test)?

Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
Where exactly are we going to use inner classes? I've looked through a good bit of the API and haven't seen one place where inner classes were used. I don't have any real world experience, so maybe you use inner classes in every program on the job, I don't know. I just fail to see where using an inner class is the best way to go.


Michael J Bruesch<br /><i>I code, therefore I am.</i>
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
allright, I have to clarify a little. I know from experience that anonymous classes come in very handy, but aside from those.
shweta agarwal
Greenhorn

Joined: Aug 30, 2001
Posts: 10
everytime instead of making a class outside the main class and then making an object to access its functions , you can use inner classes.
for eg: inner classes can be very effectively used when u write codes using event handling.
eg2: while using GrifBag layout manager.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

In addition to the two uses above, I also use them alot when I'm using threads... you get all the advantages of a Runnable object ( i.e. local attribute and method calls ) , but you can have more than one run() method...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

You would use an inner class anytime you wanted to hide a class from everyone else.
I have not used them a lot but I ran into one example in which they were helpful. I had a class on which I wanted to keep some simple statistics. I wanted all the statistics code to live in its own class, but didn't want anyone else to use this statistics class. So I made this stats code an inner class.

Please ignore post, I have no idea what I am talking about.
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

I use them when instantiating TreeMap with a sort algorithm.

Pho


Regards,

Pho
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where are Inner Classes used (except for the SCJP test)?