You can also overload methods by keeping the same number of parameters but changing their types.
public static String describe(int value) {
return "Integer: " + value;
}
public static String describe(double value) {
return "Double: " + value;
}
public static String describe(String value) {
return "String: " + value;
}
Calling describe(42) invokes the int version. Calling describe(3.14) invokes the double version. Calling describe("hello") invokes the String version.
Be careful with automatic type widening. If you call describe('A'), Java widens the char to an int, so the int version runs. This can surprise you if you expected a different overload to match.