Method overloading : overloading method « Object Oriented « SCJP






Overloaded methods can change return types; 
overridden methods cannot, except in the case of covariant returns.

Overloading means reusing a method name, but with different arguments.

Overloaded methods May have different return types, if argument lists are also different

Overloaded methods May have different access modifiers

Overloaded methods May throw different exceptions

Methods from a superclass can be overloaded in a subclass.

Polymorphism applies to overriding, not to overloading.


public void changeSize(int size, String name, float pattern) { }

The following methods are legal overloads of the changeSize() method:

public void changeSize(int size, String name) { }
public int changeSize(int size, float pattern) { }
public void changeSize(float pattern, String name)throws IOException { }

The following are all different methods:

public void aMethod(String s) { }
public void aMethod() { }
public void aMethod(int i, String s) { }
public void aMethod(String s, int i) { }

Only the argument types are considered, not their names

public void aMethod(int j, String name) { } would not be distinguished from 
public void aMethod(int i, String s) { }.








6.5.overloading method
6.5.1.Method overloading
6.5.2.Be careful to recognize when a method is overloaded rather than overridden.
6.5.3.Invoking overloaded methods:
6.5.4.Method overloading and class hierarchy
6.5.5.Differences Between Overloaded and Overridden Methods
6.5.6.A difference in return type is insufficient to constitute an overload.
6.5.7.Different list of thrown exceptions is insufficient to constitute an overload.
6.5.8.A method is identified by its fully qualified class name, the method name, and the exact sequence of its argument types.
6.5.9.Overloading is the re-use of a method name in the one class or subclass for a different method.
6.5.10.Overloaded methods supplement each other; an overriding method replaces the method it overrides.
6.5.11.Overloaded methods can exist, in any number, in the same class.
6.5.12.The return type of an overloaded method may be chosen freely
6.5.13.Overloaded methods may have different return types.
6.5.14.Overloaded methods have the same name but different arguments.