Page 1 of 1

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

Posted: Mon Nov 25, 2013 3:44 pm
by pawmot
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.

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

Posted: Mon Nov 25, 2013 4:46 pm
by admin
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.

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

Posted: Sat Oct 25, 2014 7:56 am
by marsh.reddy
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?

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

Posted: Sat Oct 25, 2014 10:04 am
by admin
If you define the argument as String[] strs, you can't call the method by doing stringProcessor("a", "b"), for example.