• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner class  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When do you need to use Inner class? in which cases?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java tutorials explain inner classes (here). After reading that, what didn't you get?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read some where it is used more in swing.I want to know the best man main usage of that
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are often used in swing but also in the Collection classes (Iterators). To quote from K&B:
Sometimes, though, you find yourself designing a class where you discover you need behaviour that belongs in a separate, specialized class, but also needs to be intimately tied to the class you're designing
From instance event handlers or iterators.
 
Stephan van Hulst
Saloon Keeper
Posts: 7961
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, you use an inner class if it performs some sort of service for the containing class, and that class alone. You can always make it a separate class in the package, but then it's visible to all other classes in the same package.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!