Just to be clear I'll state the question: "Which of the following correctly defines a method named stringProcessor that can be called by other programmers as follows: stringProcessor(str1) or stringProcessor(str1, str2) or stringProcessor(str1, str2, str3), where str1, str2, and str3 are references to Strings.".
The question bank lists this answer as correct: "public void stringProcessor(String... strs){ }". I think that's wrong, and here's why: the question does not ask for method that can be called with an arbitrary number of arguments (including none). It very clearly asks for the possibility of calling it with 1, 2 or 3 arguments of type String. Hence, I think that the last answer ("Three separate methods need to be written.") is correct.
I agree that the question is open to interpretation - it does not state that the list is exhaustive. Nevertheless, I think that my interpretation is more logically sound - if the list is not exhaustive, then why assume that stringProcessor(str1, str2, str3, int1) should not be included?
My main point here is not that one answer or the other is correct, but that the question is vague. Please correct it.
About Question enthuware.ocajp.i.v7.2.1293 :
Moderator: admin
-
- Posts: 3
- Joined: Mon Nov 25, 2013 3:31 pm
- Contact:
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1293 :
The question does not say that these are the only three possibilities. It just says that a programmer must be able to call it as the three mentioned signatures and the given method does allow those 3 possibilities.
I agree that it could be seen as a little vague but you can expect that in the exam as well. I think it would better to leave the question as it is and leave this discussion here so that a reader and view both the view points.
HTH,
Paul.
I agree that it could be seen as a little vague but you can expect that in the exam as well. I think it would better to leave the question as it is and leave this discussion here so that a reader and view both the view points.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sat Oct 18, 2014 7:08 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1293 :
What's wrong with passing a list of strings, ie the third option:
public void stringProcessor(String[] strs){ }
You could pass in as many as you want, but they will be ordered in a list, which will be even more useful?
public void stringProcessor(String[] strs){ }
You could pass in as many as you want, but they will be ordered in a list, which will be even more useful?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1293 :
If you define the argument as String[] strs, you can't call the method by doing stringProcessor("a", "b"), for example.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 244 guests