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 When to use inner classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "When to use inner classes?" Watch "When to use inner classes?" New topic
Author

When to use inner classes?

Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36
Hi,
Can you anyone please tell me when should i go for inner classes? How does it help if i use an inner class replacing a separate class?
Sanjeev Dubey
Greenhorn

Joined: Aug 07, 2008
Posts: 16
hi Shaik,

There are lots of discussion done on the SCJP side of Java ranch..
you can follow it up there...
its quite interesting and with lots of real time examples.

hope that helps

Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36
Thanks sanjeev
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Its common to use an inner class when adding an ActionEvent to a listener, for example in Swing. This removes the need to conditionally test what button has been clicked in a function to designate the appropriate action: A quick sketch example would be....

J


The inner class would then extend the relevant abstract classes for action-Events and the overridden method ActionPerformed() will handle the button click. Take a look also on the Swing Forums here at the ranch.

be a well encapsulated person, don't expose your privates, unless you public void getWife()!
 
GeeCON Prague 2014
 
subject: When to use inner classes?