What are the rules for method overloading versus overriding, and can you overload a method by changing only the return type?
Last updated
Overloading: same name, different parameter list (count, types, or order) in the same scope. It is resolved at compile time by argument types.
Overriding: same signature as an inherited method with identical or covariant return type, no more restrictive access, and no broader checked exceptions. It is resolved at runtime.
You cannot overload by return type alone: a call like
foo()gives the compiler no way to choose, so it's a compile error.