English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Scala can specify default parameter values for function parameters. When default parameters are used, you do not need to pass parameters during the function call process. In this case, the function will call its default parameter value. If parameters are passed, the passed values will replace the default values. An example is as follows:
object Test { def main(args: Array[String]) { println( "Return Value : " + addInt() ); } def addInt( a:Int=5, b:Int=7 ) : Int = { var sum:Int = 0 sum = a + b return sum } }
Execute the above code, the output will be:
$ scalac Test.scala $ scala Test Return Value : 12