Hi there
I have so doubts about the following question
When can we use same method name in
java for two different methods
A. If the two methods are in two unrelated classes.
B. If the two methods are in the same class and they differ in argument & return type.
C. If one method is in base class, other is in its subclass and the two methods differ only in return type.
D. If one method is in base class, other is in its sub class and the two methods differ both arguments list and in return type.
The answer given is A, B and D.
IMHO, when we want to use same method name for two methods it means we want to do overloading. According to my knowledge return type is not part of a method signature. Thus it is not taken account when a method is overload.
As such, statement B is not entirely correct becuase it is possible to differ in argument type only. Am I right?? Are A and D the best answer for this question.
Thanks a lot.