Nested class and Inner class in Kotlin
Kotlin Miscellaneous : Nested Class and Inner Class

Just like java, we can define nested class in Kotlin as well. In java — a nested class is by default an “inner” class.

Inner class — It’s a part of the OuterClass instance, It has access to everything inside the Outer class. i.e. instance of NestedClass can reach into the scope of OuterClass instance, and access its members, including its methods and properties.
In Kotlin, by default a nested class is not an inner class, its acts more like a static property.

In the above code snippet, NestedClass is not able to access the count field from the OuterClass. Also, in both Java and Kotlin to access an inner class we need an instance of outer class, but here we are accessing the nested class similar the way we access static fields in Java.
In Kotlin, to make a nested class an inner class, we have to use a keyword inner.

Note: Inner class cause garbage collection problem, as Inner class has an implicit reference to the outer class, hence the outer class cannot be garbage-collected while we are holding on to the inner class.
I hope you enjoyed reading my article and learnt something new. if you have any suggestions or want me to cover any topic, feel free to drop a comment.
Thank you!✌️