Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/when-cannot-add-to-a-generic-collection
Question 88 / 297:  The following code contains a compilation error, at what line?
import java.util.ArrayList;

import java.util.List;

interface Chewable {}

class Meat implements Chewable {}

public class Tester {

public static void main(String[] args) {

List<? extends Chewable> list1 = new ArrayList<Meat>(); // Line 11

List<Chewable> list2 = new ArrayList<Chewable>(); // Line 13

Meat meat = new Meat();

list1.add(meat); // Line 17

list2.add(meat); // Line 19

}

}

A  Line 11
B  Line 13
C  Line 17
D  Line 19
<< First < Previous Next > Last >>
Explanation:

You cannot add to a collection declared using wild card '?'

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>