overloading Flashcards
overloading
allows methods to have the same name in the same class
how java determines which method to call when multiple methods have the same name
it is based on the method signatures
signature
name, static or instance, parameters (not return type) (what about visability modifier?)
what is the signature for this:
public float doSomething(intx);
doSomething(int)
prototype of a method
signature with a return type and any additional modifiers
parameter type promotion
if you give java an integer when it expected a double (or anything more precise), it will promote the integer to a double
public voidfooBar( intx, doubley ) { … } public voidfooBar( doubleu, intv ) { … } …
fooBar( 10, 23.0 );// okay, use the first
fooBar( 10.0, 23 );// okay, use the second
fooBar( 10, 23 ); // java does not know which int to promote (compile-time error)