Page 1 of 1

About Question enthuware.ocajp.i.v7.2.939 :

Posted: Thu Dec 06, 2012 5:13 am
by ETS User
Correct answer say "If there is another method with the same name but with a different number of arguments in a class then that method can be called as overloaded."

But, explanation of another answer is "....So if the parameter list of the two methods with the same name are different either in terms of number or in terms of the types of the parameters, then they are overloaded."


So, correct answer must be ".... but with a different number of arguments or different types in a class then ...."

Re: About Question enthuware.ocajp.i.v7.2.939 :

Posted: Thu Dec 06, 2012 6:34 am
by admin
The given option statement is talking about only one specific case in a particular class i.e. when the method name is same and it has different number of parameters. In such a case, the method is indeed overloaded. Therefore it is a correct option. This option is not talking about all the cases.

The explanation explains the complete rule.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.939 :

Posted: Wed Apr 17, 2013 10:57 am
by insider
In explanation to the option "An overloaded method means a method..." I suggest it is necessary to add that return types should be the same since if they're somehow different it would not be a valid overriding.

Re: About Question enthuware.ocajp.i.v7.2.939 :

Posted: Wed Apr 17, 2013 6:33 pm
by admin
insider wrote:In explanation to the option "An overloaded method means a method..." I suggest it is necessary to add that return types should be the same since if they're somehow different it would not be a valid overriding.
Actually, return types can be different. Not completely differently but co-variant different. i.e. an overriding method may return a subclass of return type of the overridden method.

If you have any other return type, it would not compile at all. So if your name and method parameters are same, you are forced to make the return type same (or co-variant).

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.939 :

Posted: Thu Apr 18, 2013 2:00 am
by insider
Overall, sounds reasonable.
admin wrote:an overriding method may return a subclass of return type of the overridden method
Thx for this remark.