Hello,
Methods cannot be overloaded based on the return types alone. That makes sense as the compiler will not be in a position to differentiate which method is invoked.
In the case of overriding something similar is applicable. Why cannot a method which is overriding in a derived class not permitted to have a different return type? The compiler will be able to make out the overriding method but then why does it care about the return types matching?
Cheers,
Raj.
Methods cannot be overloaded based on the return types alone. That makes sense as the compiler will not be in a position to differentiate which method is invoked.
In the case of overriding something similar is applicable. Why cannot a method which is overriding in a derived class not permitted to have a different return type? The compiler will be able to make out the overriding method but then why does it care about the return types matching?
Cheers,
Raj.