Functional and object-oriented programming in Kotlin
Kotlin can achieve many more things with function because Kotlin is also a functional programming language. Functional programming is a programming paradigm where functions can also be used as variables, arguments and return values of other functions. Put simply, functional programming considers functions as first-class citizens.
Kotlin is also an object-oriented programming language. Essentially, everything in Kotlin is an object! Additionally, Kotlin has complete support for encapsulation, polymorphism and inheritance.
The following Kotlin code shows the definition of a simple class using the class keyword: >>> class myClass { ... val s1: Int = 100 ... val s2: String = “My String” ... }
The presented class, which is called myClass, contains two properties, called s1 and s2. However, as you’ll learn in a forthcoming tutorial myClass is far from complete! Please note that methods in classes, myClass has no methods at the moment, and can be private, which means that they can only be called by the other methods of the class, or public, which means that they can also be called from the outside world.
A forthcoming tutorial will talk about the object-oriented capabilities of Kotlin in more detail, where you’ll learn how to use existing classes and create more complex objects.