October 2018
Intermediate to advanced
370 pages
9h 15m
English
If you have worked with C# or Java, you're likely to be already familiar with the declaration of a class inside a class. Kotlin provides a similar feature with more functionalities, which is useful when we need to encapsulate the functionalities of one class. Let's start with normal nested classes. Create a class called Outer with one property, out, and one function, info(). Now, create a nested class called Nested with one property, nest, and one function, info(). Both of the info functions in the Outer and Nested classes display messages on the screen:
class Outer{ val out = "Outer class" fun info() { println("I am an outer class function") } fun getNestedClass() : Nested{ return Nested() } class Nested { val nest = "Nested ...
Read now
Unlock full access