Recall & Review
beginner
What is an inner class in Kotlin?An inner class in Kotlin is a class defined inside another class that can access the members of its outer class directly.Click to reveal answer
intermediate
How does an inner class access the outer class's members?An inner class can access the outer class's properties and functions directly using the <code>this@OuterClassName</code> syntax if needed.Click to reveal answer
beginner
What keyword is used to declare an inner class in Kotlin?The <code>inner</code> keyword is used before the class declaration to make it an inner class that holds a reference to the outer class.Click to reveal answer
intermediate
What happens if you declare a nested class without the <code>inner</code> keyword?A nested class without <code>inner</code> is static and cannot access the outer class's members directly.Click to reveal answer
intermediate
Show how to access an outer class property named <code>name</code> from an inner class in Kotlin.Inside the inner class, use
this@OuterClass.name to access the outer class's name property.Click to reveal answer
Which keyword makes a Kotlin nested class an inner class with access to outer members?
✗ Incorrect
The
inner keyword allows the nested class to access the outer class's members.How do you refer to the outer class instance from inside an inner class?
✗ Incorrect
Use
this@OuterClassName to explicitly refer to the outer class instance.What is true about a nested class without the
inner keyword?✗ Incorrect
A nested class without
inner is static and cannot access outer class members.Which of these is a valid way to declare an inner class in Kotlin?
✗ Incorrect
The correct syntax is
inner class InnerClass {}.Why would you use an inner class instead of a nested class?
✗ Incorrect
Inner classes hold a reference to the outer class and can access its members.
Explain how an inner class in Kotlin can access the members of its outer class. Include syntax examples.
Think about how the inner class keeps a reference to the outer class instance.
You got /3 concepts.
Describe the difference between a nested class and an inner class in Kotlin regarding access to outer class members.
Focus on the presence or absence of the inner keyword.
You got /3 concepts.