Inner Classes Flashcards
1
Q
What is a nested class?
A
A class that is declared inside another class.
2
Q
Why do we use nested classes?
A
Logical grouping: if one class is useful only to one other class, then we can nest them together in one file.
Encapsulation: Nested classes increase encapsulation.
Code Clarity: Makes the code more readable, only top-level classes are exposed. Helper classes are kept hidden.
3
Q
What is a nested interface?
A
A nested interface is an interface that is declared inside another interface. By default it is static. It is also known as a static interface.
4
Q
Can an Interface be defined in a Class?
A
Yes we can define a Static Nested interface within a class. Only the enclosing class can access it.