Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to use inner classes?

 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sanjeev
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic