Defining classes

To define a class, we have to use the class keyword. All of the classes in Kotlin are final by default, and if we want to extend a class, we should declare it with the open keyword. A class that holds the readOnly and mutable variables, as well as the changeMutable method, may look like this:

class Foo {
val readOnly = 3
var mutable = 3

fun changeMutable() {
mutable = 4
}
}

It is worth mentioning that a function that is a class member is called a method. In this way, we can explicitly specify that a function belongs to a class. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.189.67