1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 148


Given the code fragments:

and

What is the result?

Show Answer
Correct Answer: BD

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

6 comments
Sign in to comment
sansay61Option: B
Dec 23, 2020

B- compilation error. printvalues must be static

jduarteOption: B
Feb 6, 2021

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)

ayzoOption: B
Jan 25, 2021

true B

r1muka5Option: B
Apr 4, 2023

Actual answer is B because the method should be static

steefaandOption: B
Feb 7, 2024

B is correct.

DarGrinOption: B
Jun 2, 2024

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

DarGrin
Jun 2, 2024

Sorry, and be static