October 2018
Intermediate to advanced
370 pages
9h 15m
English
A class that is declared with the inner keyword is called an inner class in Kotlin. Let's extend the previous example by creating an Outer class with one additional property, called counter. Add the inner keyword with the Nested class and create an incrementCounter() that increases the counter value. Remember that the counter is not a Nested class property but instead an Outer class member. The Nested class is declared as an inner class so the members of the Outer class are directly accessible:
class Outer { val out = "Outer class" var counter = 0 fun info() { println("I am an outer class function") } inner class Nested { val nest = "Nested class" fun info() { println("I am a nested class function") } fun incrementCounter(){ ...
Read now
Unlock full access