nerdexam
Oracle

1Z0-851 · Question #217

Given: import java.util.*; public class Hancock { // insert code here list.add("foo"); } } Which two code fragments, inserted independently at line 5, will compile without warnings? (Choose two.)

The correct answer is B. public void addStrings(List<String> list) { C. public void addStrings(List<? super String> list) {. See the full explanation below for the reasoning.

Question

Given: import java.util.*; public class Hancock { // insert code here list.add("foo"); } } Which two code fragments, inserted independently at line 5, will compile without warnings? (Choose two.)

Options

  • Apublic void addStrings(List list) {
  • Bpublic void addStrings(List<String> list) {
  • Cpublic void addStrings(List<? super String> list) {
  • Dpublic void addStrings(List<? extends String> list) {

How the community answered

(44 responses)
  • A
    7% (3)
  • B
    80% (35)
  • D
    14% (6)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice