October 2018
Intermediate to advanced
370 pages
9h 15m
English
Function-overloading is a feature where a class has more than one function with the same names. Each function is uniquely identified by its parameters. In the following example, a Person class contains two functions with the same name – fun greet(), which doesn't contain any parameters, and fun greet(message : String), which contains one string parameter. Kotlin can determine the function call by the parameters provided:
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 greet(message : String){ println("Hi I am $name.... $message") } fun greet(){ println("Hi I am $name.... Nice to meet you!!!") }}fun
Read now
Unlock full access