About Question enthuware.ocpjp.v7.2.1120 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
D3x!

About Question enthuware.ocpjp.v7.2.1120 :

Post by D3x! »

just curious, as String cannot be extended surely it can only be of type String and nothing else?

Code: Select all

List<? extends String>
list is a List of some class that extends from String. It may not necessarily be String. Therefore, you cannot add a String to list.

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

Re: About Question enthuware.ocpjp.v7.2.1120 :

Post by admin »

What you say is correct but it does not apply to declarations that use generics. Ideally, compiler should not even allow List<? extends String> because String is final. But I guess it might lead to complications if, for example, a class is later on made non-final (or final) and that is why it does not check whether the class is final or not.

HTH,
Paul.

D3x!

Re: About Question enthuware.ocpjp.v7.2.1120 :

Post by D3x! »

great point thanks.

lbunschoten

Re: About Question enthuware.ocpjp.v7.2.1120 :

Post by lbunschoten »

Very hard to answer this question correctly as none of the answers compile. A String can't be added to a list which requires a Shape. Also the methods have a parameter 'strList'. You would expect a list of Strings. However in all examples it is a list of Shapes. Even if you would replace Shape with String for each individual parameter, it would still leave you with four incorrect options.

So I assume there is something wrong with this question or am I doing something wrong?

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

Re: About Question enthuware.ocpjp.v7.2.1120 :

Post by admin »

You are right. This question was modified recently to use Shape instead of String and that introduced the error.
The line :

Code: Select all

list.add("extra");
should actually be

Code: Select all

list.add(new Shape());

Options 2 and 3 are correct based on that.

This should be fixed asap.

thank you for your feedback.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest