Home Search Jobs Govt JobsNew Resume Makernew Career Guidance Ask n Answer Student Ambassadors


  Ask n Answer
  Ask a Question
0 out of 300 characters

nesting of class in class in
By kuldeep singh (Beginner)  8 years ago   28 views
 Your Answer
0 out of 1250 character
Share |
Report Abuse
Hello Kuldeep,

Here's the brief explanation about the nested class in

There are several compelling reasons for using nested classes, among them:

It is a way of logically grouping classes that are only used in one place.
It increases encapsulation.
Nested classes can lead to more readable and maintainable code.
Logical grouping of classes—If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such 'helper classes' makes their package more streamlined.

Increased encapsulation—Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.

More readable, maintainable code—Nesting small classes within top-level classes places the code closer to where it is used.

I would suggest you to take a look of example to understand better.

Good Luck !!
Know a better answer? Click here to post.

Ask & Answer
Panel of Experts

All rights reserved © 2021 Info Edge (India) Ltd.