next up previous
Next: 1.4.6 The Command Pattern Up: 1.4 Java Classes and Previous: 1.4.4 Inheritance and the

1.4.5 Method Overloading

In Java, the same name can simultaneously be used for several different methods. For example, a class can have multiple methods named toString. When several methods have the same name, Java must be able to distinguish them by their parameter types. When such a method is invoked, Java determines the types of the method arguments and uses this information to select the ``best'' (most specific) match from among the alternatives. If no best method, the program is ill-formed and will be rejected by the Java compiler.

This approach to accommodating multiple methods with the same name is called method overloading.



Robert Cartwright, Spring 1999