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

Given the code fragment:

What is the result?

    Correct Answer: D

    The code results in a compilation error at line n2 because the UnaryOperator<String> requires a String input, but strBuf is of type StringBuffer. The method apply for UnaryOperator<String> expects a String argument, and passing a StringBuffer causes a type mismatch.

Discussion
jduarteOption: D

Answer is D. The method apply(String) in the type Function<String,String> is not applicable for the arguments (StringBuffer). c.appy(strBuff) is not correct.

HanenBAOption: D

UnaryOperator<String> c accept a string as input not StringBuffer, so c.apply(strBuf) will cause a compilation error

Tarik2190Option: D

Answer is D, public class Test { public static void main (String[] args) { final String str1 = "Java"; StringBuffer strBuf = new StringBuffer("Course"); UnaryOperator<String> u = (str2) -> str1.concat(str2); UnaryOperator<String> c = (str3) -> str3.toLowerCase(); System.out.println(u.apply(strBuf)); } }

pul26Option: D

Answer is D strBuf is not a String

Svetleto13Option: D

D,tested

asdfjhfgjuaDCVOption: D

D is the correct answer

steefaandOption: D

Answer is D. UnaryOperator takes a String and not StringBuffer.

hmcbqOption: A

Answer is A. If lambda has parenthesis than parameter should be with type.