| Java supports method name overloading so
that multiple methods can share the same name. |
| For example |
| |
class DataRenderer
{
void draw(String s)
{
. . .
}
void draw(int i)
{
. . .
}
void draw(float f)
{
. . .
}
} |
| |
| |
| Overloaded methods are differentiated by the number and type of the
arguments passed into the method. |
| In the code sample, draw(String s) and draw(int i) are distinct
and unique methods because they require different argument types. |
| We cannot declare more than one method with the same
name and the same number and type of arguments because the
compiler cannot differentiate them. So, draw(String s) and draw(String t) are identical and result in a compiler error. |
| |
| A class may override a method in its superclass.
The overriding method must have the same name, return type, and
parameter list as the method it overrides. |