Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what are nested classes for?

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'd like to know what are nested classes like static member class, non-static member class, local class and anonymous class for?
I believe each of them have a different purposes.
could somebody please help me out?

Thank you
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


so .... u wanna know y would one use a nested class ...right .....first of all lemm me tell ya ....(i dont have programmin experience ) ...but as far as i know ....they are rarely used ...and when used ...they are mostly used in case of event handlings .... one simple reason y they are not used is ...coz they complicate the code ... they are used for basic two reasons ...:

1) u might need to make use of the special functionality of classs A from within class B without complicating the hierarchy of either classes ...(take some time in analizing these lines ) ...

2) if u r a programmer , then u might think .... if there is a class A ..that solely exists to help class B ... y write "class B extends A" ....y not get class A inside class B ... and may be u could use b to extend some other class .... this would help all the code to stay in a single file also ....

got it .... u might take some time actually if u have not dealt with event handling ...even i took some time in these ....

bye
 
Simon Baker
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner classes are not as useless as the last post suggests.

If you wish a class, A, to have access to objects of another class, B, then you reference them. If class B is only relevant to class A, and would have no meaning outside class A, then you make it an inner class.

The inheritance hierarchy expresses the "is a" relationship. Thus, stating that class A extends B is stating that A is a more specialised version of B. This is quite different to stating that B encapsulates behaviour relevant only to class A.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic