943,739 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2605
  • Java RSS
Jul 2nd, 2009
0

What is the Use of Inner classes

Expand Post »
Can any one justify the use of inner classes with example(if possible)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
painless is offline Offline
7 posts
since Apr 2008
Jul 2nd, 2009
0

Re: What is the Use of Inner classes

To be visible to just parent class.
C# Syntax (Toggle Plain Text)
  1. namespace Example
  2. {
  3. class Parent
  4. {
  5. void Method()
  6. {
  7. Child c = new Child();//No error
  8. }
  9. class Child
  10. {
  11. }
  12. }
  13. class Painless
  14. {
  15. void Method()
  16. {
  17. Child c = new Child();//error
  18. }
  19. }
  20. }
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jul 2nd, 2009
0

Re: What is the Use of Inner classes

Sometimes you need an instance of a class - eg as a Listener for a Swing Event,, or a Runnable for a Thread - and these are most conveniently and compactly created locally as inner classes, often anonymous inner classes.
Featured Poster
Reputation Points: 1907
Solved Threads: 950
Posting Expert
JamesCherrill is offline Offline
5,768 posts
since Apr 2008
Jul 2nd, 2009
0

Re: What is the Use of Inner classes

And inner classes can provide specific functionality for their parent classes. There are relevant examples in the Sun tutorials on inner classes.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Student Assignment
Next Thread in Java Forum Timeline: Multiple threads





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC