In this tutorial, we will learn about the Function overloading in Kotlin. Same as Java Methods we can overload function in Kotlin. To overload a function in Kotlin, the function must have the same name and parameter lists should be different(in data type or in numbers). Check out the following example program.
Page Contents
Example Program:
//overloaded function
fun addition(num1: Int, num2: Int): Int{
return num1+num2
}
//overloaded function
fun addition(num1: Double, num2: Double): Double{
return num1+num2
}
fun main (args: Array<String>){
var ans=addition(10,20) //calling the addtion function with int values
println("Ans = "+ans)
var ans2=addition(21.5,11.2) //calling the addtion function with double values
println("Ans = "+ans2)
}
Output:
Ans = 30
Ans = 32.7
As in above example, you can see particular function is invoking on function call according to the parameter we are passing while calling the function,
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
