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

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

Moderator: admin

Post Reply
pawmot
Posts: 3
Joined: Mon Nov 25, 2013 3:31 pm
Contact:

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

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

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

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

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

marsh.reddy
Posts: 1
Joined: Sat Oct 18, 2014 7:08 am
Contact:

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

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

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

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

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 244 guests