package com.includehelp
//Declare class
class Operation{
//Member function with two Int type Argument
fun sum(a:Int, b:Int){
println("Sum($a,$b) = ${a+b}")
}
//Overloaded Member function
//with three Int type Argument
fun sum(a:Int, b:Int,c:Int){
println("Sum($a,$b,$c) = ${a+b+c}")
}
//Overloaded Member function with
//four Int type Argument
fun sum(a:Int, b:Int,c:Int,d:Int){
println("Sum($a,$b,$c,$d) = ${a+b+c+d}")
}
}
//Main function, entry Point of Program
fun main(args:Array<String>){
//Create Instance of Operation class
val operation = Operation()
//Called function with two arguments
operation.sum(10,20)
//Called function with three arguments
operation.sum(a=2,b=3,c=5)
//Called function with four arguments
operation.sum(5,8,2,12)
}
Program for method overloading in Kotlin
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer