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 ...."
About Question enthuware.ocajp.i.v7.2.939 :
Moderator: admin
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.939 :
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.
The explanation explains the complete rule.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Wed Apr 17, 2013 9:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.939 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.939 :
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.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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Wed Apr 17, 2013 9:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.939 :
Overall, sounds reasonable.
Thx for this remark.admin wrote:an overriding method may return a subclass of return type of the overridden method
Who is online
Users browsing this forum: No registered users and 232 guests