Overloaded Method Overridden Method
Argument(s) Must change. Must not change.
Return type Can change. Can't change except for covariant returns.
Exceptions Can change. Can reduce or eliminate. Must not throw new or broader checked exceptions.
Access Can change. Must not make more restrictive (can be less restrictive).
public class MainClass {
public static void main(String[] argv) {
System.out.println(calc(1, 2));
System.out.println(calc(1.1F, 2.2F));
}
public static int calc(int a, int b) {
System.out.println("int");
return a + b;
}
public static float calc(float a, float b) {
System.out.println("float");
return a + b;
}
}
|