Inner Classes Flashcards

1
Q

What is a nested class?

A

A class that is declared inside another class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly