Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas

PatilShreyas/InnerDemo.kt Secret

Last active Jan 15, 2021
Embed
What would you like to do?
class Outer {
val value = 10
class Inner1 {
fun accessOuter() = println("Outer value = $value") // ❌ Can't access value of Outer class.
}
inner class Inner2 {
fun accessOuter() = println("Outer value = $value") // ✅ Can access value of Outer class.
}
}
fun main() {
Outer.Inner1().accessOuter() // #1
Outer().Inner2().accessOuter() // #2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment