8 KFun
8 KFun
Types of Function
Kotlin standard library function
Kotlin user-dened function
Kotlin Default arguments
Content
1 Kotlin Function
2 Types of Function
3 Kotlin standard library function
4 Kotlin user-dened function
Creating user-dened function
Calling of user-dened function
5 Kotlin Default arguments
No arguments are passed while calling a function
Kotlin Function
We can call sum(x, y) at any number of times and it will return sum of two numbers. So,
function avoids the repetition of code and makes the code more reusable.
Types of Function
Continue....
Continue....
Explanation: We have dened a function above starting with fun keyword whose return type is
an Integer.
The arguments which need not specify explicitly while calling a function are
called default arguments. If the function is called without passing
arguments then the default arguments are used as function parameters. In
other cases, if arguments are passed during a function call then passed
arguments are used as function parameters.
There are three cases for default arguments-
1 No arguments are passed while calling a function