0

I'm learning Kotlin at school and it is beig quite difficult to me. I was given this example of code but I'm not understanding at all what it does, specially the part marked as a comment. I hope you can help me. Thanks

open class W{
    open fun f(){
        println("en W.f()")
    }
}


class X : W(){
    override fun f(){
        println("en X.f")
    }
// FROM HERE
    inner class Y{
        fun g() {
            super@X.f()
            f()
// UNTIL HERE
        }
    }
}

fun main() {
    val x = X()
    x.Y().g()
}
  • 1
    You may find it helpful to see [the language documentation](https://kotlinlang.org/docs/reference/nested-classes.html#inner-classes), and other questions here such as [this one](https://stackoverflow.com/questions/59436139/what-is-the-purpose-of-inner-class-in-kotlin). – gidds Oct 05 '20 at 11:48

1 Answers1

0

There's a class inside of X called Y. If you look in main, you are creating an X, and then creating a Y through the dot access, and then running the g that is a member of Y.

Carlos
  • 5,991
  • 6
  • 43
  • 82