nerdexam
Oracle

1Z0-851 · Question #157

Given: 3. import java.util.*; 4. public class G1 { 5. public void takeList(List<? extends String> list) { 6. // insert code here 7. } 8. } Which three code fragments, inserted independently at line…

The correct answer is B. Object o = list; C. String s = list.get(0); D. list = new ArrayList<String>(). See the full explanation below for the reasoning.

Question

Given: 3. import java.util.*; 4. public class G1 { 5. public void takeList(List<? extends String> list) { 6. // insert code here 7. } 8. } Which three code fragments, inserted independently at line 6, will compile? (Choose three.)

Options

  • Alist.add("foo");
  • BObject o = list;
  • CString s = list.get(0);
  • Dlist = new ArrayList<String>();
  • Elist = new ArrayList<Object>();

How the community answered

(45 responses)
  • A
    7% (3)
  • B
    76% (34)
  • E
    18% (8)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice