What is an 'Inner Class' (or Nested Class), and when is it conceptually appropriate to use one?
Last updated
A nested class is defined inside another class to express tight coupling. A non-static inner class is tied to an outer instance, while a static nested class is just a namespaced helper.
Use it when the type only makes sense within its enclosing class (e.g.
NodeinsideLinkedList) or for one-off callbacks. This keeps implementation types hidden.Non-static inner classes hold an implicit reference to the outer object and can leak memory, so prefer static nesting unless the outer instance is needed.