16.11 Nested and Inner Classes
Kotlin allows one class to be nested within another class. In the following code, for example, ClassB is nested inside ClassA:
class ClassA {
class ClassB {
}
}
In the above example, ClassB does not have access to any of the properties within the outer class. If access is required, the nested class must be declared using the inner directive. In the example below ClassB now has access to the myProperty variable belonging to ClassA:
class ClassA {
var myProperty: Int = 10
inner class ClassB {
val result = 20 + myProperty
}
}