jyothi sudi wrote:What is the need for nested classes in java?
Other than the fact that for things like anonymous classes, it's "the way Java does things", I'm not sure that you can really describe it as a 'need'.
What it is though is
very useful.
Can anyone give a real time example
AbstractMap.SimpleEntry, which actually implements a nested
interface - also very useful.
or simple program how it makes any difference when the same action is performed using an external class?
And that's where the problem comes: Any program that uses a nested class can be written to use a top-level class; but it
won't be as good.
Quite apart from the question of why you would write
Map.Entry as anything
but a nested interface; the fact is that nested classes are allowed to do and "see" things that normal classes aren't, which helps with information-hiding.
To me, it also just makes sense: An
Entry doesn't have any meaning except
with a
Map, so why not define it inside the class?
HIH
Winston