Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 98

Given:

and

Which two lines can replace line 1 so that the Y class compiles? (Choose two.)

    Correct Answer: C, E

    The Y class contains a method that overrides the set method from the X class, but with a Map<String, String> parameter instead of a Collection parameter. The goal is to replace line 1 with a statement that correctly compiles. Both options C and E meet the criteria since the map.values() method returns a Collection, which aligns with the parameter type expected by the set method in the superclass. Option C calls the set method with map.values(), satisfying the method signature in class X. Similarly, option E uses super.set(map.values()) to invoke the superclass method with a Collection parameter, ensuring the code compiles.

Discussion
ASPushkinOptions: CD

answer: CED D correct this is the recursion public void set(Map<String,String> map) { set(map); } CE correct Map Collection<V> values() so Map Collection<V> values() set(Collection<String>) - Ok

OmnisumemOptions: CE

Tested: C, E.

dillemanOptions: CE

C and E

StavokOptions: CE

The two lines that can replace line 1 so that the Y class compiles are C. set(map.values()) and E. super.set(map.values()). Option C is correct because it calls the set() method with the result of calling the values() method on the map object, which returns a Collection of the values in the map. Option E is correct because it calls the set() method in the superclass (Question98) with the result of calling the values() method on the map object, which returns a Collection of the values in the map.