Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 116

Given:

and the code fragment:

Which two code fragments, when inserted at line n1 independently, enable the code to print TruckCarBike?

    Correct Answer: D, E

    To print the vehicles in the order Truck, Car, Bike, they need to be sorted by the vehicle IDs in ascending order, which are 1, 2, and 3 respectively. When printing, they will appear as Truck, Car, Bike based on the given IDs. Option D uses Integer.compare to compare the vehicle IDs correctly, ensuring that the vehicles are sorted in the required order. Option E utilizes Comparator.comparing to achieve the same, sorting the vehicles by their IDs. Both options D and E correctly sort the vehicles by their IDs, allowing them to print in the correct order.

Discussion
laura_lu93Options: DE

correct are D and E. tested! because C print their ID not their Name

mevlt

Actually C is Runtime Exception because Vehicle class doesn't implement Comparable interface.

Eason_from_the_future

B should be ".sorted(Comparator.comparing(Vehicle::getvName).reversed())"

asdfjhfgjuaDCVOptions: DE

D and E are the correct answer

steefaandOptions: DE

D and E are correct.

lnrdgstOption: E

I believe that the letter D is also incorrect because there is no method v2.getVid() but v2.getVId(). If alternative D had the call to method v2.getVId it would be right. No other alternative compiled, unfortunately only letter E is true by my tests.