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

Given the code fragments:

and

What is the result?

    Correct Answer: B

    The code will result in a compilation error. The method printValues() in the class Test does not take any arguments, yet it is being referenced in the context of forEach, which requires a Consumer function that accepts a String argument. Additionally, printValues() is not a static method, but the forEach call attempts to use method references that would necessitate either a static method or an instance method that matches the expected signature.

Discussion
jduarteOption: B

Answer B. Tested . t.getList().forEach(Test::printValues) Multiple markers at this line - The type Test does not define printValues(String) that is applicable here - The method forEach(Consumer<? super String>) in the type Iterable<String> is not applicable for the arguments (Test1::printValues)

sansay61Option: B

B- compilation error. printvalues must be static

ayzoOption: B

true B

DarGrinOption: B

Answer B. Method printValues() should take a String and be public like this: public static void printValues(String s) {System.out.println(s);}

DarGrin

Sorry, and be static

steefaandOption: B

B is correct.

r1muka5Option: B

Actual answer is B because the method should be static