• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Usage of Inner class

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I always wonder what is the actual use of Inner classes in Java.

I thought about it and came up with one use...dont know whether this is correct or not

If there is a logic that could be actually separated from another class, and if it is not worth of creating a new object...may be due to memory management...then Inner class is the solution...

Is this actually correct??

Appreciate your time on this qn.
 
Marshal
Posts: 80768
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't sound a good design. Inner classes have nothing to do with memory management. The inner class represents something which is closely related to the outer class. So a LinkedList class would have a (probably nested) LinkedNode class.
 
Ravi Kiran Savirigana
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Campbell,
Thankyou very much for the reply. The comment i made earlier is just a guess...

But I still dont understand why, even if a class is very close to another class, why cant it be in a new class, rather than in the same class. Is there any specific reason...My doubt is ...why a new concept...if we can go with the older one...which is already a good OO approach..
 
Campbell Ritchie
Marshal
Posts: 80768
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be no need for the inner class to be available to other classes. A LinkedList does not need to expose its inner ListNode class.
 
Ravi Kiran Savirigana
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell,
Thanks for the reply...now I got it...May be...if you dont want to expose your class to others...and you want to keep it seperately ifrom your class...then Inner Class is the solution...
May be a type of security???
reply
    Bookmark Topic Watch Topic
  • New Topic