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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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 ...."

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 255 guests