Nested Class (Not inner Class)
Nested classes (static by default) do NOT have a reference to the outer object in Kotlin. The outer class acts as a namespace.
class Outer {
class Nested {
fun doSomething() {
println("Doing something in Nested")
}
}
// Outer class members
fun outerMethod() {
println("Outer method")
}
}
// Usage
fun main() {
// Create instances independently
val outer = Outer()
val nested = Outer.Nested() // Note: using Outer as namespace
// They are completely independent
outer.outerMethod()
nested.doSomething()
// You can create Nested without creating Outer
val justNested = Outer.Nested()
}