About Question enthuware.ocpjp.v25.2.1445 :

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

Moderator: admin

Post Reply
AlienFS
Posts: 11
Joined: Tue Sep 05, 2023 4:07 am
Contact:

About Question enthuware.ocpjp.v25.2.1445 :

Post by AlienFS »

The provided context:

Code: Select all

The signature of a method in a class is as follows:
public static <E extends CharSequence> List<? super E> doIt(List<E> nums)

This method is being called in the following code:
result = doIt(in);
The question:
"Given that String implements CharSequence interface, what should be the reference type of in and result variables?"

It is not specifically stated that String* is used as an input parameter and thus I consider this irrelevant information.
As a result I expect that any class that IS-A CharSequence* can be provided as input.

Yet the answer states this is valid:
input = ArrayList<String> in
--> This answer, however, does not support all cases of IS-A CharSequence* and thus should not be a valid answer at all.

* As type in a List.

Is this question a case of "the exam can contain a question with similar wording and I am simply training you to be aware of it."?

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

Re: About Question enthuware.ocpjp.v25.2.1445 :

Post by admin »

This question is a Foundation level question, which are mostly theoretical. These are not particularly an exam style questions. They are meant to make sure you understand the basics.

Now, coming to the subject matter of this question - You are expected to declare variables in and result such that the given method can be invoked. If you declare them like this (as given in the correct option):
ArrayList<String> in;
List result;

Can you call the given method? In other words, will the following line compile?
result = doIt(in);

The answer is yes, it will. So this is the correct answer.

>It is not specifically stated that String* is used as an input parameter and thus I consider this irrelevant information. As a result I expect that any class that IS-A CharSequence* can be provided as input.

You are misreading the question. It tells the reader that "String implements CharSequence" only to make sure that the reader is aware of this relationship and they be able to answer the question while fully knowing this fact. If one doesn't know this factoid then they cannot answer this question.

Further, yes, any class that IS-A CharSequence can be provided as input . For example, if class XYZ implements CharSequence then
ArrayList<XYZ> in; List result; will work too. But ArrayList<XYZ> is not provided in any of the options. ArrayList<String> is. And it works fine with the given constraints.

Post Reply