原创转载请注明出处:http://agilestyle.iteye.com/blog/2333242
The term overload refers to the name of a method: You use the same name (“overload” that name) for different methods as long as the argument lists differ.
package org.fool.scala.overloading class Overloading1 { def f(): Int = 88 def f(n: Int): Int = n + 2 } class Overloading2 { def f(): Int = 99 def f(n: Int): Int = n + 3 } object Overloading extends App { val o1 = new Overloading1 val o2 = new Overloading2 println(o1.f()) println(o1.f(11)) println(o2.f()) println(o2.f(11)) }
Console Output