October 2018
Intermediate to advanced
370 pages
9h 15m
English
Every sealed class is tagged with the sealed keyword and is limited to a set of classes that can be declared inside the class body. Here is an example of a sealed class:
sealed class A(val number : Int) { class B(n: Int) : A(n) { fun display() { println("number = $number" ) }} class C(n: Int) : A(n){ fun square() { println("Square = "+ number * number) } } }
class A is a sealed class and class B and class C are the classes that are inherited from class A. Before Kotlin 1.1, declaring a child class inside a sealed class was the only method of declaration. Now, however, we can extend the sealed class from outside the class body, as shown in the preceding example, where class C extends class A. Remember that both the sealed and ...
Read now
Unlock full access