GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes what are nested classes for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what are nested classes for?" Watch "what are nested classes for?" New topic
Author

what are nested classes for?

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
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

Joined: Sep 15, 2004
Posts: 88


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


Impossible is I M Possible
Simon Baker
Ranch Hand

Joined: Sep 09, 2004
Posts: 57
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.
 
GeeCON Prague 2014
 
subject: what are nested classes for?