Created
August 31, 2019 16:38
-
-
Save harshgmp/051181598b1042fa990b55e5b7c4f761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* firstParam is of the type Integer which is called Int | |
* secondParam is of the type Int | |
* The last Int after colon and before the opening bracket of method is the return type, which is Int in our case | |
*/ | |
fun multiply(firstParam : Int, secondParam : Int): Int { | |
return firstParam * secondParam | |
} | |
/** | |
* This function is same as above except that we do not have | |
* to explicitly declare the return type | |
*/ | |
fun multiplyWithInferredReturnType(firstParam : Int, secondParam : Int) = firstParam * secondParam | |
/** | |
* This function is same as above except that we have explicitly mentioned return type as Unit | |
* which means none. | |
*/ | |
fun multiplyWithUnitReturnType(firstParam : Int, secondParam : Int) : Unit { | |
println("${firstParam * secondParam}") | |
} | |
/** | |
* This function is same as above except that we have not explicitly mentioned return type as Unit | |
* which means none. | |
*/ | |
fun multiplyWithNoReturnType(firstParam : Int, secondParam : Int) { | |
println("${firstParam * secondParam}") | |
} | |
fun main() { | |
println(multiply(10, 10)) | |
println(multiplyWithInferredReturnType(13,10)) | |
multiplyWithUnitReturnType(9,7) | |
multiplyWithNoReturnType(11,9) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment