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>
Joined: Sep 23, 2001
allright, I have to clarify a little. I know from experience that anonymous classes come in very handy, but aside from those.
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.
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...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
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.