What is the Use of Inner classes

Reply

Join Date: Apr 2008
Posts: 7
Reputation: painless is an unknown quantity at this point 
Solved Threads: 0
painless painless is offline Offline
Newbie Poster

What is the Use of Inner classes

 
0
  #1
Jul 2nd, 2009
Can any one justify the use of inner classes with example(if possible)
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: What is the Use of Inner classes

 
0
  #2
Jul 2nd, 2009
To be visible to just parent class.
  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. }
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 964
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 143
JamesCherrill JamesCherrill is online now Online
Posting Shark

Re: What is the Use of Inner classes

 
0
  #3
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,529
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 190
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: What is the Use of Inner classes

 
0
  #4
Jul 2nd, 2009
And inner classes can provide specific functionality for their parent classes. There are relevant examples in the Sun tutorials on inner classes.
I am so hungry. :(
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC