Complete the code to access the outer class property from the inner class.
class Outer { val greeting = "Hello" inner class Inner { val greeting = "inner" fun greet() = [1] } }
In Kotlin, to access an outer class member from an inner class, use this@Outer.
Complete the code to call the outer class function from the inner class.
class Outer { fun outerFun() = "Outer Function" inner class Inner { fun outerFun() = "inner" fun callOuter() = [1] } }
outerFun() directly calls the inner class function.Use this@Outer.outerFun() to call the outer class function from the inner class.
Fix the error in accessing the outer property inside the inner class method.
class Outer { val number = 42 inner class Inner { val number = 0 fun printNumber() { println([1]) } } }
number or this.number accesses the inner class property.Use this@Outer.number to correctly access the outer class property.
Fill both blanks to access outer class property and call its function from inner class.
class Outer { val text = "Hi" fun outerFun() = "Called" inner class Inner { val text = "inner" fun outerFun() = "inner func" fun combined() = [1] + " " + [2]() } }
Use this@Outer.text to access the property and this@Outer.outerFun() to call the function.
Fill all three blanks to create a map with outer property keys and inner class method results as values.
class Outer { val prefix = "Key" inner class Inner { fun suffix() = "Value" fun createMap() = mapOf([1] to [2].[3]()) } }
this@Outer to call inner methods causes errors.The map key is the outer property prefix. The value calls the inner class method suffix() using this.suffix().