Ashesh PDF
Ashesh PDF
Introduction
Nested Class
Nested Class
Description
There are two main types of nested classes:
Types
Nested Class
Merits
Logical Grouping:
Nested classes allow for logical grouping of classes
that are only used within
Encapsulation:
Nested classes can access the private members of their
enclosing class,
which enhances encapsulation.
Namespace Management:
By nesting classes, you avoid polluting the global
namespace.
Enhanced Readability:
Nested classes can make the code easier to understand by
showing the relationship between the nested and
enclosing classes clearly.
Nested Class
Demerits
Increased Complexity:
Nested classes can add an extra layer of complexity to
the code.
Tight Coupling:
Inner classes are tightly coupled with their enclosing
classes,
which can lead to less modular code