One way to overload a method is by changing the number of parameters. This is common when you want a default behavior alongside a customizable one.
public static void log(String message) {
System.out.println("[INFO] " + message);
}
public static void log(String message, String level) {
System.out.println("[" + level + "] " + message);
}
Calling log("started") uses the -parameter version and prints [INFO] started. Calling log("failed", "ERROR") uses the -parameter version and prints [ERROR] failed.
Java matches the call to the method signature with the same number and types of arguments. If no match exists, the compiler gives an error.