November 2018
Intermediate to advanced
388 pages
9h 5m
English
Classes in Kotlin are created using the class keyword, which is depicted as follows:
class User {}
The structure of the class is as follows:
Class className { //properties and constructor //member functions}
Let's write a class for User.
Consider the following code for 14_Class.kts:
class User { var name = "George"}val user = User()println(user.name)
The output is as follows:

This class has a property called name. Classes are instantiated with just the class name, followed by parentheses. Note that there is no new keyword in Kotlin to create an object, unlike in Java.
Classes in Kotlin are final by default. We cannot extend ...
Read now
Unlock full access