October 2018
Intermediate to advanced
370 pages
9h 15m
English
In this section, we will have a quick look at how behaviors and functions can be implemented. We will continue with our Person class, which has three behaviors—speak, eat, and walk.
As we know, class behaviors are represented by functions. We can declare a function within the class body:
class Person (val name: String, var age : Int , var height : Double) { fun speak() { println("My name is $name , i am $age years old and I am $height feet tall") }}fun main(args: Array<String>) { val abid = Person("Abid", 40, 6.0) abid.speak()}
Read now
Unlock full access